1 .\" Copyright (c) 2003 Tim Kientzle
2 .\" All rights reserved.
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\" notice, this list of conditions and the following disclaimer.
9 .\" 2. Redistributions in binary form must reproduce the above copyright
10 .\" notice, this list of conditions and the following disclaimer in the
11 .\" documentation and/or other materials provided with the distribution.
13 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 .\" $FreeBSD: src/usr.bin/tar/bsdtar.1,v 1.28 2005/04/19 16:06:04 murray Exp $
32 .Nd manipulate tape archives
35 .Op Ar bundled-flags Ao args Ac
36 .Op Ao Ar file Ac | Ao Ar pattern Ac ...
40 .Op Ar files | directories
45 .Op Ar files | directories
52 creates and manipulates streaming archive files.
54 The first synopsis form shows a
57 This usage is provided for compatibility with historical implementations.
58 See COMPATIBILITY below for details.
60 The other synopsis forms show the preferred usage.
63 is a mode indicator from the following list:
64 .Bl -tag -compact -width indent
66 Create a new archive containing the specified items.
70 but new entries are appended to the archive.
71 Note that this only works on uncompressed archives stored in regular files.
76 List archive contents to stdout.
80 but new entries are added only if they have a modification date
81 newer than the corresponding entry in the archive.
82 Note that this only works on uncompressed archives stored in regular files.
87 Extract to disk from the archive.
88 If a file with the same name appears more than once in the archive,
89 each copy will be extracted, with later copies overwriting (replacing)
98 mode, each specified file or directory is added to the
99 archive in the order specified on the command line.
100 By default, the contents of each directory are also archived.
102 In extract or list mode, the entire command line
103 is read and parsed before the archive is opened.
104 The pathnames or patterns on the command line indicate
105 which items in the archive should be processed.
106 Patterns are shell-style globbing patterns as
110 Unless specifically stated otherwise, options are applicable in
112 .Bl -tag -width indent
113 .It Cm @ Ns Pa archive
115 The specified archive is opened and the entries
116 in it will be appended to the current archive.
118 .Dl Nm Fl c Fl f Pa - Pa newfile Cm @ Ns Pa original.tar
119 writes a new archive to standard output containing a file
121 and all of the entries from
124 .Dl Nm Fl c Fl f Pa - Pa newfile Pa original.tar
125 creates a new archive with only two entries.
127 .Dl Nm Fl czf Pa - Fl -format Cm pax Cm @ Ns Pa -
128 reads an archive from standard input (whose format will be determined
129 automatically) and converts it into a gzip-compressed
130 pax-format archive on stdout.
133 can be used to convert archives from one format to another.
134 .It Fl b Ar blocksize
135 Specify the block size, in 512-byte records, for tape drive I/O.
136 As a rule, this argument is only needed when reading from or writing
137 to tape drives, and usually not even then as the default block size of
138 20 records (10240 bytes) is very common.
139 .It Fl C Ar directory
140 In c and r mode, this changes the directory before adding
142 In x mode, change directories after opening the archive
143 but before extracting entries from the archive.
144 .It Fl -check-links ( Fl W Cm check-links )
146 Issue a warning message unless all links to each file are archived.
147 .It Fl -exclude Ar pattern ( Fl W Cm exclude Ns = Ns Ar pattern )
148 Do not process files or directories that match the
150 Note that exclusions take precedence over patterns or filenames
151 specified on the command line.
152 .It Fl -format Ar format ( Fl W Cm format Ns = Ns Ar format )
154 Use the specified format for the created archive.
155 Supported formats include
161 Other formats may also be supported; see
162 .Xr libarchive-formats 5
163 for more information about currently-supported formats.
165 Read the archive from or write the archive to the specified file.
168 for standard input or standard output.
169 If not specified, the default tape device will be used.
170 (On FreeBSD, the default tape device is
172 .It Fl -fast-read ( Fl W Cm fast-read )
174 Extract or list only the first archive entry that matches each pattern
176 Exit as soon as each specified pattern or filename has been matched.
177 By default, the archive is always read to the very end, since
178 there can be multiple entries with the same name and, by convention,
179 later entries overwrite earlier entries.
180 This option is provided as a performance optimization.
183 Symbolic links named on the command line will be followed; the
184 target of the link will be archived, not the link itself.
192 .It Fl -include Ar pattern ( Fl W Cm include Ns = Ns Ar pattern )
193 Process only files or directories that match the specified pattern.
194 Note that exclusions specified with
196 take precedence over inclusions.
197 If no inclusions are explicitly specified, all entries are processed by
201 option is especially useful when filtering archives.
202 For example, the command
203 .Dl Nm Fl c Fl f Pa new.tar Fl -include='*foo*' Cm @ Ns Pa old.tgz
204 creates a new archive
206 containing only the entries from
208 containing the string
212 Compress the resulting archive with
214 In extract or list modes, this option is ignored.
215 Note that, unlike other
217 implementations, this implementation recognizes bzip2 compression
218 automatically when reading archives.
221 Do not overwrite existing files.
222 In particular, if a file appears more than once in an archive,
223 later copies will not overwrite earlier copies.
226 All symbolic links will be followed.
227 Normally, symbolic links are archived as such.
228 With this option, the target of the link will be archived instead.
232 is specified in the environment, this is a synonym for the
235 Otherwise, an error will be displayed.
236 Users who desire behavior compatible with GNU tar should use
242 Do not extract modification time.
243 By default, the modification time is set to the time stored in the archive.
246 Do not recursively archive the contents of directories.
247 .It Fl -newer Ar date ( Fl W Cm newer Ns = Ns Ar date )
249 Only include files and directories newer than the specified date.
250 This compares ctime entries.
251 .It Fl -newer-mtime Ar date ( Fl W Cm newer-mtime Ns = Ns Ar date )
255 except it compares mtime entries instead of ctime entries.
256 .It Fl -newer-than Pa file ( Fl W Cm newer-than Ns = Ns Pa file )
258 Only include files and directories newer than the specified file.
259 This compares ctime entries.
260 .It Fl -newer-mtime-than Pa file ( Fl W Cm newer-mtime-than Ns = Ns Pa file )
264 except it compares mtime entries instead of ctime entries.
265 .It Fl -nodump ( Fl W Cm nodump )
267 Honor the nodump file flag by skipping this file.
268 .It Fl -null ( Fl W Cm null )
274 Filenames or patterns are separated by null characters,
276 This is often used to read filenames output by the
282 In extract (-x) mode, files will be written to standard out rather than
283 being extracted to disk.
284 In list (-t) mode, the file listing will be written to stderr rather than
288 Use the user and group of the user running the program rather
289 than those specified in the archive.
290 Note that this has no significance unless
292 is specified, and the program is being run by the root user.
293 In this case, the file modes and flags from
294 the archive will be restored, but ACLs or owner information in
295 the archive will be discarded.
296 .It Fl -one-file-system ( Fl W Cm one-file-system )
298 Do not cross mount points.
301 By default, absolute pathnames (those that begin with a /
302 character) have the leading slash removed both when creating archives
303 and extracting from them.
306 will refuse to extract archive entries whose pathnames contain
308 or whose target directory would be altered by a symlink.
309 This option suppresses these behaviors.
312 Preserve file permissions.
313 Attempt to restore the full permissions, including owner, file modes, file
314 flags and ACLs, if available, for each item extracted from the archive.
315 By default, newly-created files are owned by the user running
317 the file mode is restored for newly-created regular files, and
318 all other types of entries receive default permissions.
321 is being run by root, the default is to restore the owner unless the
323 option is also specified.
324 .It Fl -strip-components Ar count ( Fl W Cm strip-components Ns = Ns Ar count )
326 Remove the specified number of leading path elements.
327 Pathnames with fewer elements will be silently skipped.
328 Note that the pathname is edited after checking inclusion/exclusion patterns
329 but before security checks.
333 will read the list of names to be extracted from
337 will read names to be archived from
341 on a line by itself will cause the current directory to be changed to
342 the directory specified on the following line.
343 Names are terminated by newlines unless
348 also disables the special handling of lines containing
352 Unlink files before creating them.
355 overwrites existing files, which preserves existing hardlinks.
356 With this option, existing hardlinks will be broken, as will any
357 symlink that would affect the location of an extracted file.
359 Produce verbose output.
360 In create and extract modes,
362 will list each file name as it is read from or written to
366 will produce output similar to that of
370 options will provide additional detail.
371 .It Fl W Ar longopt=value
372 Long options (preceded by
374 are only supported directly on systems that have the
379 option can be used to access long options on systems that
380 do not support this function.
382 Ask for confirmation for every action.
384 Read a list of exclusion patterns from the specified file.
387 for more information about the handling of exclusions.
390 Compress the resulting archive with
392 In extract or list modes, this option is ignored.
393 Note that, unlike other
395 implementations, this implementation recognizes bzip2 compression
396 automatically when reading archives.
399 Compress the resulting archive with
401 In extract or list modes, this option is ignored.
402 Note that, unlike other
404 implementations, this implementation recognizes gzip compression
405 automatically when reading archives.
408 The following environment variables affect the execution of
410 .Bl -tag -width ".Ev BLOCKSIZE"
415 for more information.
416 .It Ev POSIXLY_CORRECT
417 If this environment variable is defined, the
419 option will be interpreted in accordance with
422 The default tape device.
425 option overrides this.
427 The timezone to use when displaying dates.
430 for more information.
433 .Bl -tag -width ".Ev BLOCKSIZE"
435 The default tape device, if not overridden by the
437 environment variable or the
444 The following creates a new archive
447 that contains two files
451 .Dl Nm Fl czf Pa file.tar Pa source.c Pa source.h
453 To view a detailed table of contents for this
455 .Dl Nm Fl tvf Pa file.tar
457 To extract all entries from the archive on
458 the default tape drive:
461 To move file hierarchies, invoke
464 .Dl Nm Fl cf Pa - Fl C Pa srcdir\ . | Nm Fl xpBf Pa - Fl C Pa destdir
465 or more traditionally
466 .Dl cd srcdir \; Nm Fl cf Pa -\ . | ( cd destdir \; Nm Fl xpBf Pa - )
468 In create mode, the list of files and directories to be archived
469 can also include directory change instructions of the form
471 and archive inclusions of the form
472 .Cm @ Ns Pa archive-file .
473 For example, the command line
474 .Dl Nm Fl c Fl f Pa new.tar Pa foo1 Cm @ Ns Pa old.tgz Cm -C Ns Pa /tmp Pa foo2
475 will create a new archive
480 from the current directory and add it to the output archive.
481 It will then read each entry from
483 and add those entries to the output archive.
484 Finally, it will switch to the
488 to the output archive.
494 switches accept a variety of common date and time specifications, including
495 .Dq 12 Mar 2005 7:14:29pm ,
496 .Dq 2005-03-12 19:14 ,
499 .Dq 19:14 PST May 1 .
501 The bundled-arguments format is supported for compatibility
502 with historic implementations.
503 It consists of an initial word (with no leading - character) in which
504 each character indicates an option.
505 Arguments follow as separate words.
506 The order of the arguments must match the order
507 of the corresponding characters in the bundled command word.
509 .Dl Nm Cm tbf 32 Pa file.tar
510 specifies three flags
519 flags both require arguments,
520 so there must be two additional items
524 is the argument to the
528 is the argument to the
532 The mode options c, r, t, u, and x and the options
533 b, f, l, m, o, v, and w comply with SUSv2.
535 For maximum portability, scripts that invoke
537 should use the bundled-argument format above, should limit
552 On systems that support getopt_long(), additional long options
553 are available to improve compatibility with other tar implementations.
555 Certain security issues are common to many archiving programs, including
557 In particular, carefully-crafted archives can request that
559 extract files to locations outside of the target directory.
560 This can potentially be used to cause unwitting users to overwrite
561 files they did not intend to overwrite.
562 If the archive is being extracted by the superuser, any file
563 on the system can potentially be overwritten.
564 There are three ways this can happen.
567 has mechanisms to protect against each one,
568 savvy users should be aware of the implications:
569 .Bl -bullet -width indent
571 Archive entries can have absolute pathnames.
576 character from filenames before restoring them to guard against this problem.
578 Archive entries can have pathnames that include
583 will not extract files containing
585 components in their pathname.
587 Archive entries can exploit symbolic links to restore
588 files to other directories.
589 An archive can restore a symbolic link to another directory,
590 then use that link to restore a file into that directory.
591 To guard against this,
593 checks each extracted path for symlinks.
594 If the final path element is a symlink, it will be removed
595 and replaced with the archive entry.
598 is specified, any intermediate symlink will also be unconditionally removed.
605 will refuse to extract the entry.
607 To protect yourself, you should be wary of any archives that
608 come from untrusted sources.
609 You should examine the contents of an archive with
610 .Dl Nm Fl tf Pa filename
614 option to ensure that
616 will not overwrite any existing files or the
618 option to remove any pre-existing files.
619 You should generally not extract archives while running with super-user
625 disables the security checks above and allows you to extract
626 an archive while preserving any absolute pathnames,
628 components, or symlinks to other directories.
637 .Xr libarchive-formats 5 ,
640 There is no current POSIX standard for the tar command; it appeared
645 The options used by this implementation were developed by surveying a
646 number of existing tar implementations as well as the old POSIX specification
647 for tar and the current POSIX specification for pax.
649 The ustar and pax interchange file formats are defined by
655 command appeared in Seventh Edition Unix.
656 There have been numerous other implementations,
657 many of which extended the file format.
660 public-domain implementation (circa November, 1987)
661 was quite influential, and formed the basis of GNU tar.
662 GNU tar was included as the standard system tar
663 in FreeBSD beginning with FreeBSD 1.0.
665 This is a complete re-implementation based on the
669 POSIX and GNU violently disagree about the meaning of the
672 Because of the potential for disaster if someone expects
673 one behavior and gets the other, the
675 option is deliberately broken in this implementation.
679 option may differ from historic implementations.
681 All archive output is written in correctly-sized blocks, even
682 if the output is being compressed.
683 Whether or not the last output block is padded to a full
684 block size varies depending on the format and the
686 For tar and cpio formats, the last block of output is padded
687 to a full block size if the output is being
688 written to standard output or to a character or block device such as
690 If the output is being written to a regular file, the last block
692 Many compressors, including
696 complain about the null padding when decompressing an archive created by
698 although they still extract it correctly.
700 The compression and decompression is implemented internally, so
701 there may be insignificant differences between the compressed output
703 .Dl Nm Fl czf Pa - file
704 and that generated by
705 .Dl Nm Fl cf Pa - file | Nm gzip
707 The default should be to read and write archives to the standard I/O paths,
708 but tradition (and POSIX) dictates otherwise.
714 modes require that the archive be uncompressed
715 and located in a regular file on disk.
716 Other archives can be modified using
722 To archive a file called
726 you must specify it as
732 In create mode, a leading
737 is stripped unless the
741 There needs to be better support for file selection on both create
744 There is not yet any support for multi-volume archives or for archiving
747 Converting between dissimilar archive formats (such as tar and cpio) using the
749 convention can cause hard link information to be lost.
750 (This is a consequence of the incompatible ways that different archive
751 formats store hardlink information.)
753 There are alternative long options for many of the short options that
754 are deliberately not documented.