Tar игнорировать ошибки

Let’s say I do this tar cfzp home.tar.gz /home (takes a while) and a file changes during compression and tar fails, I get «file changed as we read it» and tar stops. I assume home.tar.gz is now incomplete, or was that just the «notice» and not really an error?

Is there some kind of «force» option to make tar finish its work and not abort on errors?

Edit/update: I found «—ignore-failed-read do not exit with nonzero on unreadable files» and at least I think it’s working. But need to be careful with the order of the parameters because you can end up with a tar file called «—ignore-failed-read»

Do I need to ignore anything else?

Update: Without «—ignore-failed-read» tar will keep going if a file has been removed «File removed before we read it». However, I think it might be aborting on the «file changed as we read it» error but I don’t really know. Hard to compare the archive to the «original» as I have cache files that come and go, etc.

Update: Upon closer observation «file changed as we read it» is more like a notice, it appears tar will keep going if files change while tar is doing its business. But I’ll leave the answer open, maybe someone more experienced can add more insight.

I have written a little script that tars and compresses a list of directories + files.

The script appears to run succesfully, in that a useable .tar.gz file is created after the script runs.

However, I get this annoying message after the script finishes:

tar: Exiting with failure status due
to previous errors

I do not see any error messages whilst the script is working, and like I said, the produced file can be uncompressed with no warnings/errors. Since I am using this as part of my backup, I want to make sure that I am not ignoring something serious.

What are the possible reasons that this error/warning message is being produced — and can I safely ignore it?. If I cant ignore it, what are the steps to diagnose and resolve the error?

I am running on Ubuntu 10.0.4

asked Jul 29, 2010 at 7:17

morpheous's user avatar

You will get that message if, for any reason, tar can’t add all of the specified files to the tar. One if the most common is not having read permission on one of the files. This could be a big problem since you are using this for backup. If you are using the -v flag, try leaving it off. This should reduce the output and let you see what is going on.

answered Jul 29, 2010 at 11:22

KeithB's user avatar

KeithBKeithB

9,9962 gold badges23 silver badges17 bronze badges

3

The problem is the f argument. It takes the next value as the filename, so it must be the last argument:

tar cvzf output.tgz folder

or:

tar -cvzf output.tgz folder

These are both the same and don’t produce an error.

Worthwelle's user avatar

Worthwelle

4,56811 gold badges21 silver badges32 bronze badges

answered Jan 28, 2013 at 9:21

Andrea Monni's user avatar

1

Sometimes backing up files that might change during the backup like logfiles, you might find useful the tar option ‘—ignore-failed-read’ (I’m on Debian Linux, not sure for non gnu tar).

Standard output and error can be redirected in 2 different files with something like:

LOGDIR='/var/log/mylogdir' 
LOG=${LOGDIR}/backup.log 
ERRLOG=${LOGDIR}/backup.error.log 
DATE=$(date +%Y-%m-%d)
HOSTNAME=$(hostname)
DATA_DIRS='/etc /home /root'

tar --ignore-failed-read -f ${BACKUP_DIR}/${HOSTNAME}-${DATE}.tgz -cvz ${DATA_DIRS} > $LOG 2> $ERRLOG

I find this to be generally safe, but please be careful though as tar won’t stop …

answered Jan 17, 2014 at 12:24

Fabio Pedrazzoli's user avatar

0

I was having the same issue and none of the above answers worked for me. However, I found that running the following command worked:

tar -cpzf /backups/fullbackup.tar.gz --exclude=backups --exclude=proc --exclude=tmp --exclude=mnt --exclude=sys --exclude=dev --exclude=run /

The errors that were being referred to in tar: Exiting with failure status due to previous errors can be identified by turning off the -v option. Upon review, the errors came from directories like /run and /sys.

By excluding these directories, it works just fine. Hope this helps anyone with a similar issue.

answered Oct 10, 2016 at 15:03

DomainsFeatured's user avatar

DomainsFeaturedDomainsFeatured

2091 gold badge3 silver badges9 bronze badges

I had the same problem. All i did was to remove the dash («-«) from the command.

Instead of typing it as

tar -cvfz output.tar.gz folder/

try typing it as

tar cvfz output.tar.gz folder/

I am unaware of why the dash was causing problems in my case but at least it worked.

Tak's user avatar

Tak

3032 silver badges5 bronze badges

answered Sep 10, 2011 at 23:06

jack's user avatar

4

You have misunderstood an earlier answer. The problem is not the -, it is where the f is in your argument list.

tar cvfz target.tgz <files>

Will try to create an archive called «z», as that is the text after f. The error message is because tar can’t find «target.gz» to add to archive «z».

tar cvzf target.tgz <files>

Will correctly create target.tgz and add files to it. This is because target.tgz is the first text after the f argument.

Jamie Taylor's user avatar

Jamie Taylor

1,4013 gold badges18 silver badges27 bronze badges

answered Oct 19, 2013 at 7:52

Thornbury's user avatar

1

Usually you can ignore that message. If there are any changes (such as file deletions/creations/modifications) to underlying directory tree during tar creation, it will throw that message. Also if there special files like device nodes, fifos and so on, they will cause that warning.

Are you sure you can’t see any culprit files? Try with tar cvfz yourtarball.tgz /your/path

answered Jul 29, 2010 at 7:26

Janne Pikkarainen's user avatar

I had a similar issue untarring a file I had received. Turns out I didn’t have permission to write the files in the archive owned by root. Using sudo fixed it.

answered Apr 23, 2019 at 18:33

ttwalkertt's user avatar

You must log in to answer this question.

Not the answer you’re looking for? Browse other questions tagged

.

Я написал небольшой скрипт, который копирует и сжимает список каталогов + файлов.

Сценарий, по-видимому, успешно выполняется, поскольку после запуска сценария создается полезный файл .tar.gz.

Тем не менее, я получаю это надоедливое сообщение после завершения скрипта:

tar: выход с состоянием ошибки из-за предыдущих ошибок

Я не вижу никаких сообщений об ошибках во время работы скрипта, и, как я уже сказал, созданный файл может быть распакован без предупреждений / ошибок. Поскольку я использую это как часть своей резервной копии, я хочу убедиться, что я не игнорирую что-то серьезное.

Каковы возможные причины появления этого сообщения об ошибке / предупреждения, и могу ли я смело его игнорировать? Если я не могу игнорировать это, каковы шаги для диагностики и устранения ошибки?

Я работаю на Ubuntu 10.0.4

Вы получите это сообщение, если по какой-либо причине tar не сможет добавить все указанные файлы в tar. Один из наиболее распространенных — отсутствие разрешения на чтение одного из файлов. Это может быть большой проблемой, так как вы используете это для резервного копирования. Если вы используете флаг -v , попробуйте отключить его. Это должно уменьшить выход и позволить вам увидеть, что происходит.

проблема в аргументе, в качестве аргумента f аргумент f принимает имя файла, поэтому он должен быть последним аргументом

tar cvzf output.tgz folder

или же

tar -cvzf output.tgz folder

то же самое и не принимать ошибку.

ответ дан Andrea Monni201

Иногда при резервном копировании файлов, которые могут изменяться во время резервного копирования, таких как файлы журналов, вам может быть полезен параметр tar ‘—ignore-failed-read’ (я работаю в Debian Linux, не уверен, что он не относится к gnu tar).

Стандартный вывод и ошибка могут быть перенаправлены в 2 разных файла что-то вроде:

LOGDIR='/var/log/mylogdir' 
LOG=${LOGDIR}/backup.log 
ERRLOG=${LOGDIR}/backup.error.log 
DATE=$(date +%Y-%m-%d)
HOSTNAME=$(hostname)
DATA_DIRS='/etc /home /root'

tar --ignore-failed-read -f ${BACKUP_DIR}/${HOSTNAME}-${DATE}.tgz -cvz ${DATA_DIRS} > $LOG 2> $ERRLOG

Я считаю, что это в целом безопасно, но, пожалуйста, будьте осторожны, поскольку tar не остановится …

ответ дан Fabio Pedrazzoli61

У меня возникла та же проблема, и ни один из приведенных выше ответов не помог мне. Однако я обнаружил, что работает следующая команда:

tar -cpzf /backups/fullbackup.tar.gz --exclude=backups --exclude=proc --exclude=tmp --exclude=mnt --exclude=sys --exclude=dev --exclude=run /

Ошибки, на которые ссылались в tar: Exiting with failure status due to previous errors можно определить, отключив опцию -v. После проверки ошибки пришли из каталогов вроде /run и /sys .

Исключая эти каталоги, он работает просто отлично. Надеюсь, что это поможет любому с подобной проблемой.

ответ дан DomainsFeatured149

У меня такая же проблема. Все, что я сделал, это удалил черту («-«) из команды.

Вместо того, чтобы печатать как

tar -cvfz output.tar.gz folder/

попробуйте ввести это как

папка tar cvfz output.tar.gz /

Я не знаю, почему черта вызывала проблемы в моем случае, но по крайней мере это работало.

Вы неправильно поняли предыдущий ответ. Проблема не в - , это где f находится в вашем списке аргументов.

tar cvfz target.tgz <files>

Постараюсь создать архив с именем «z», так как это текст после f . Сообщение об ошибке вызвано тем, что tar не может найти «target.gz» для добавления в архив «z».

tar cvzf target.tgz <files>

Будет правильно создавать target.tgz и добавлять в него файлы. Это потому, что target.tgz является первым текстом после аргумента f .

Обычно вы можете игнорировать это сообщение. Если есть какие-либо изменения (например, удаление / создание / изменение файлов) в базовом дереве каталогов во время создания tar, он выдаст это сообщение. Также, если есть специальные файлы, такие как узлы устройств, fifos и т.д., Они вызовут это предупреждение.

Вы уверены, что не видите никаких файлов преступников? Попробуйте с помощью tar cvfz yourtarball.tgz /your/path

ответ дан Janne Pikkarainen6k

Всё ещё ищете ответ? Посмотрите другие вопросы с метками ubuntu bash tar gzip.

Updated: 11/06/2021 by

tar command

On Unix-like operating systems, the tar command creates, maintains, modifies, and extracts files that are archived in the tar format.

This page covers the GNU/Linux version of tar.

Description

«Tar» stands for tape archive. It is an archiving file format.

tar was originally developed in the early days of Unix for the purpose of backing up files to tape-based storage devices. It was later formalized as part of the POSIX standard, and today is used to collect, distribute, and archive files, while preserving file system attributes such as user and group permissions, access and modification dates, and directory structures.

This documentation covers the GNU version of tar, which is included with most modern variants of the Linux operating system.

Syntax

tar [-] A --catenate --concatenate | c --create | d --diff --compare | 
    --delete | r --append | t --list | --test-label | u --update | 
    x --extract --get [options] [pathname ...]

Operation

The first argument to tar should be a function specification: either one of the letters A, c, d, r, t, u, or x, or one of the long function names. A function letter does not need to be prefixed with a dash (««), and may be combined with other single-letter options. A long function name must be prefixed with a double dash (««). Some options take a parameter; with the single-letter form these must be given as separate arguments. With the long form, they may be given by appending «=value» to the option.

For example, the following commands are all equivalent:

tar --create --file=archive.tar file1 file2
tar -c -f archive.tar file1 file2
tar -cf archive.tar file1 file2
tar cf archive.tar file1 file2

Functions

Specifying one of the following functions selects what tar‘s main mode of operation will be:

A, —catenate,
—concatenate
Append tar files to an archive.
c, —create Create a new archive.
d, —diff, —compare Calculate any differences between the archive and the file system.
—delete Delete from the archive. (This function doesn’t work on magnetic tapes).
r, —append Append files to the end of a tar archive.
t, —list List the contents of an archive.
—test-label Test the archive label, and exit.
u, —update Append files, but only those that are newer than the copy in the archive.
x, —extract, —get Extract files from an archive.

Other options

The following options specify the way tar operates:

[07][lmh] Specifies drive and density. (If you’re not sure what this means, you don’t need to use this option.)
-a, —auto-compress Use the archive’s suffix to determine the compression program. For example, if this option is specified, an archive with the extension .tar.gz is always handled as if the —gzip option had been specified (see —gzip, below).
—add-file=file Add file to the archive. (This option is especially useful when the name of the file begins with a dash.)
—anchored File name patterns must match from the beginning of a file name.
—no-anchored File name patterns may match after any «/» (this is the default for excluding files; see —exclude, below).
—atime-preserve Preserve access times on archived files, either by restoring the times, or (if the operating system supports it) not changing them in the first place.
—no-auto-compress Do not automatically determine the compression program using the archive file name suffix.
-b,
—blocking-factor BLOCKS
Use BLOCKS x 512 bytes-per-record when handling the archive.
-B, —read-full-records «Re-block» all input. This option helps read damaged archives.
—backup[=backup-method Rather than deleting files from the file system, tar will back them up using the specified backup method backup-method, which may be one of the following:

t, numbered Always make numbered backups.
nil, existing Make numbered backups of files that already have them, and simple backups of the others.
never, simple Always make simple backups.

If not specified, backup-method defaults to the value of environment variable VERSION_CONTROL; if VERSION_CONTROL is undefined, backup-method defaults to existing.

-C, —directory DIR Change to directory DIR before performing any operations.
—check-device Check device numbers when creating incremental archives. This is the default behavior.
—no-check-device Do not check device numbers when creating incremental archives.
—checkpoint[=NUMBER] Use «checkpoints»: display a progress message every NUMBER records (default 10).
—checkpoint-action=ACTION Execute ACTION at every checkpoint. ACTION may be one of the following:

bell Play an audible bell at the console.
dot, . Print a single dot.
echo Display a text message at the console (to standard error).
echo=string Display string string on standard error; before output, any metacharacters in string are expanded.
exec=command Execute the given command.
sleep=time Wait for time seconds.
ttyout=string Output string on the current console (‘/dev/tty‘).

Several —checkpoint-action options can be specified. The supplied actions will be executed in the order of their appearance on the command line.

Using —checkpoint-action without —checkpoint will assume the default checkpoint interval of 10 records.

—delay-directory-restore Delay setting modification times and permissions of extracted directories until extraction has ended.
—no-delay-directory-restore Modification times and permissions of extracted directories are set when all files from this directory are extracted. This is the default.
—exclude=PATTERN Avoid operating on files whose names match file name pattern PATTERN.
—exclude-backups Exclude backup and lock files from all operations.
—exclude-caches Causes tar to exclude all directories that contain a cache directory tag.

A cache directory tag is a short file with the name CACHEDIR.TAG and having a standard header specified in https://bford.info/cachedir/. This option excludes the contents of the directory, but archives the directory itself and the CACHEDIR.TAG file.

—exclude-caches-all Omit directories containing a CACHEDIR.TAG file entirely.
—exclude-caches-under Exclude everything under directories containing a CACHEDIR.TAG file, including the CACHEDIR.TAG file; but, archive the directory.
—exclude-tag=FILE Exclude the contents of any directory containing file FILE, but archive the directory and the file FILE.
—exclude-tag-all=FILE Omit directories containing file FILE entirely.
—exclude-tag-under=FILE Exclude everything under directories containing file FILE including the file FILE; but, archive the directory.
—exclude-vcs Exclude version control subdirectories. This option recognizes the files and directories used by many widely-used VCS systems. The files excluded are:

  • CVS/, and everything under it
  • RCS/, and everything under it
  • SCCS/, and everything under it
  • .git/, and everything under it
  • .gitignore
  • .cvsignore
  • .svn/, and everything under it
  • .arch-ids/, and everything under it
  • {arch}/, and everything under it
  • =RELEASE-ID
  • =meta-update
  • =update
  • .bzr
  • .bzrignore
  • .bzrtags
  • .hg
  • .hgignore
  • .hgrags
  • _darcs
-f, —file=ARCHIVE Use archive file (or device) ARCHIVE.
-F, —info-script,
—new-volume-script=NAME
Run script NAME at the end of each tape (implies -M).
—force-local Force tar to treat the archive file as a local file, even if its name contains a colon.
—full-time Print the full resolution of all file times.
-g, —listed-incremental=FILE During a —create operation, this option specifies that the archive be a new GNU-format incremental backup, using snapshot file FILE to determine which files to backup. With other operations, this option informs tar that the archive is in incremental format.
-G, —incremental Handle old GNU-format incremental backups.
—group=NAME Force NAME as group for added files.
-h, —dereference Follow symlinks; archive the files they point to.
-H, —format=FORMAT Create archive of the given format, where FORMAT is one of the following:

gnu GNU tar 1.13.x format.
oldgnu GNU format used in tar versions 1.12 and lower.
pax POSIX 1003.1-2001 («pax») format.
posix Same as pax.
ustar POSIX 1003.1-1988 («ustar») format.
v7 Old Unix version 7 tar format.
—hard-dereference Follow hard links; archive the files they refer to.
-i, —ignore-zeros Ignore zeroed blocks in archive. Normally an entire block of bytes with a value of zero indicates an end-of-archive; this option helps tar handle a damaged archive, or any other oddly-formed archive with blocks of zeros in its contents.
-I,
—use-compress-program=PROG
Use external compression program PROG. Use this option if you are not happy with the compression program associated with the suffix at compile time, or if you have a compression program that GNU tar does not support. The PROG argument must be a valid command, as you would type it at the command-line prompt, with any additional options as needed. Enclose it in quotes if it contains white space.

PROG should follow two conventions: First, when invoked without additional options, it should read data from standard input, compress it and output it on standard output. Secondly, if invoked with the additional ‘-d‘ option, it should do exactly the opposite: read the compressed data from the standard input and produce uncompressed data on the standard output.

The latter requirement means you must not use the ‘-d‘ option as a part of the PROG command invocation itself.

—ignore-case Ignore character case when matching patterns or file names.
—no-ignore-case Use case-sensitive pattern and file name matching (this is the default).
—ignore-command-error Ignore exit codes of subprocesses.
—no-ignore-command-error Treat non-zero exit codes of subprocesses as an error.
—ignore-failed-read Do not exit merely because an unreadable file was encountered.
—index-file=FILE Send verbose output to file FILE for later use.
-j, —bzip2 This option tells tar to read or write archives using the bzip2 compressor.
-J, —xz Tells tar to read or write archives using the xz compressor.
-k, —keep-old-files Do not overwrite existing files when extracting files from an archive, and return an error if such files exist.
-K, —starting-file=NAME This option affects extraction only; tar skips extracting files in the archive until it finds one that matches name.
—keep-newer-files Don’t replace existing files that are newer than their archive copies.
-l, —check-links Check the number of links dumped for each processed file. If this number does not match the total number of hard links for the file, print a warning message.
-L, —tape-length=size[suf] Change tape after writing a certain number of bytes. If suf is not specified, SIZE is treated as kilobytes (1024 bytes), which is equivalent to specifying suf as B. suf may be one of the following:

suffix units byte equivalent
b Blocks size x 512
B Kilobytes size x 1024
c Bytes size
G Gigabytes size x 1024^3
K Kilobytes size x 1024
k Kilobytes size x 1024
M Megabytes size x 1024^2
P Petabytes size x 1024^5
T Terabytes size x 1024^4
w Words size x 2
—level=n When using the —listed-incremental option, force an incremental backup of level n.
—lzip Read or write archives through the lzip compressor.
—lzma Read or write archives through the lzma compressor.
—lzop Read or write archives through the lzop compressor.
-m, —touch Sets the data modification time of extracted files to the extraction time, rather than the data modification time stored in the archive. In other words, touch all extracted files.
-M, —multi-volume Create, list, or extract a multi-volume archive. Such archives are broken into parts so that they may fit on media too small to contain the entire archive.
—mode=permissions When adding files to an archive, tar assigns permissions to the archive members, rather than the permissions from the files. The permissions can be specified either as an octal number or as symbolic permissions, as with chmod.
—mtime=date When adding files to an archive, tar uses date as the modification time of members when creating archives, instead of their actual modification times. The value of date can be either a textual date representation or a name of the existing file, starting with «/» or «.«, in which case the modification time of that file is used.
-n, —seek Assume that the archive media supports seeking to arbitrary locations. Usually, tar determines automatically whether the archive can be seeked or not; this option is intended for use in cases when such recognition fails. It takes effect only if the archive is open for reading with «—list» or «—extract» options).
-N, —newer, —after-date=date Only store files whose data or status has changed on or after date. If date is a file name, the date of that file is used.
—newer-mtime=date Like —after-time, but looks at modification times only.
—null When tar uses the ‘—files-from‘ option, this option instructs tar to expect file names terminated with NUL, so tar can correctly work with file names that contain newlines.
—no-null Cancels any previous —null option specified.
—numeric-owner Always use numeric IDs, rather than names, for user/group ownership information.
-O, —to-stdout Extract files to standard output.
—occurrence[=number] This option can be used in conjunction with one of the subcommands «—delete«, «—diff«, «—extract» or «—list» when a list of files is given either on the command-line or via ‘-T‘ option.

This option instructs tar to process only the numberth occurrence of each named file. The number defaults to 1, so:

tar -x -f archive.tar --occurrence filename

will extract the first occurrence of the member «filename» from «archive.tar» and will terminate without scanning to the end of the archive.

—old-archive, —portability Same as «—format=v7«.
—one-file-system Prevents tar from crossing file system boundaries when archiving. Can be used with any write operation.
—overwrite Overwrite existing files when extracting.
—overwrite-dir Overwrite metadata of existing directories when extracting (this is the default behavior).
—no-overwrite-dir Preserve metadata of existing directories when extracting.
—owner=user Specifies that tar should use user as the owner of members when creating archives, instead of the user associated with the source file. The user is a username, or a user’s numeric ID, or both as «name:id«.
-p, —preserve-permissions,
—same-permissions
When tar is extracting an archive, it normally subtracts the user’s umask from the permissions specified in the archive and uses that number as the permissions to create the destination file. Specifying this option instructs tar that it should use the permissions directly from the archive.
-P, —absolute-names Don’t strip leading «/«s from file names.
—pax-option=keyword-list Enables creation of the archive in POSIX.1-2001 format, where keyword-list is a comma-separated list of keyword options specific to that format.
—posix Same as —format=posix.
—preserve This is the same as specifying both «—preserve-permissions» and «—same-order«.
—quote-chars=STRING When displaying files and other members of an archive, tar treats file names in a special way to avoid ambiguities caused by certain characters that may occur in the file name; this is called name quoting. The —quote-chars option will, additionally, quote any characters occurring in STRING.
—no-quote-chars=STRING When name quoting, tar never quotes any of the characters in STRING.
—quoting-style=STYLE When name quoting, use name quoting style STYLE. Valid values of STYLE are: literal, shell, shell-always, c, escape, locale, and clocale. The default quoting style is escape, unless overridden while configuring the package.
-R, —block-number With this option specified, tar prints error messages for read errors with the block number in the archive file.
—record-size=siz[suf] Instructs tar to use size bytes-per-record when accessing the archive. The argument can be suffixed with a size suffix, e.g., «—record-size=10K» for 10 kilobytes.
—recursion Recurse into directories (this is the default).
—no-recursion Do not recurse into subdirectories when archiving.
—recursive-unlink Remove existing directory hierarchies before extracting directories of the same name from the archive.
—remove-files Remove files after adding them to an archive.
—restrict Disable use of some potentially harmful tar options. Currently this option disables shell invocation.
—rmt-command=cmd In cases where tar uses a remote tape server, this option notifies tar that it should use cmd as the remote tape server program instead of the default, «/usr/libexec/rmt«.
—rsh-command=cmd In cases where tar uses a remote shell to communicate with non-local devices, this option notifies tar that it should use cmd instead of the default, rsh.
-s, —preserve-order,
—same-order
This option helps when processing large lists of file names on machines with small amounts of memory. It is used in conjunction with —compare, —list or —extract.

The —same-order option tells tar that the list of file names to be listed or extracted is sorted in the same order as the files in the archive. This allows a large list of names to be used, even on a small machine that would not otherwise be able to hold all the names in memory at the same time. Such a sorted list can easily be created by running tar -t on the archive and editing its output.

This option is probably never needed on modern computer systems.

-S, —sparse This option instructs tar to test each file for sparseness before attempting to archive it. If the file is sparse it is treated specially, thus allowing to decrease the amount of space used by its image in the archive.

This option is meaningful only when creating or updating archives. It has no effect on extraction.

—same-owner Attempt to give extracted files the same ownership as exists in the archive (this is the default for superuser).
—no-same-owner Do not attempt to restore ownership when extracting. This is the default behavior for ordinary users, so this option has an effect only for the superuser.
—no-same-permissions Apply the user’s umask when extracting permissions from the archive. This is the default behavior for ordinary users.
—no-seek Do not attempt to seek to arbitrary locations within an archive.
—show-defaults Display tar‘s default options. This can be useful in certain shell scripts.
—show-omitted-dirs When listing or extracting, list each directory that does not match search criteria.
—show-transformed-names,
—show-stored-names
Display file or member names after applying any name transformations. In particular, when used in conjunction with one of the archive creation operations it instructs tar to list the member names stored in the archive, instead of the actual file names.
—sparse-version=version-number Specifies the format version to use when archiving sparse files. Implies ‘—sparse‘.
—strip-components=number Strip given number of leading components from file names before extraction. For example, if archive «archive.tar» contained a member named «/some/file/name«, then running:

tar --extract --file archive.tar --strip-components=2

would extract this file to file «name«.

—suffix=suffix Uses the file name suffix suffix when backing up files. If —suffix is not specified, the default backup suffix is the value of the environment variable DEFAULT_BACKUP_SUFFIX, or if that variable is not defined, «~«.
-T, —files-from=file tar uses the contents of file as a list of archive members or files to operate on, in addition to those specified on the command line.
—to-command=command During extraction, tar will pipe extracted files to the standard input of command.
—totals[=signum] Display byte totals when processing an archive. If signum is specified, these totals are displayed when tar receives signal number signum.
—transform, —xform=sed-expr Replace file names with sed replacement expression sed-expr. For example,

tar cf archive.tar --transform 's,^\./,usr/,'

adds to archive.tar files from the current working directory, replacing initial «./» prefix with «usr/«.

-U, —unlink-first Remove a corresponding file from the file system before extracting it from the archive, rather than overwriting it.
—unquote Unquote file names read in with -T; this is the default.
—no-unquote Do not unquote file names read in with -T.
—utc Print all file times in UTC (universal time).
-v, —verbose Operate verbosely.
-V, —label=name When creating an archive, write name as a name record in the archive. When extracting or listing archives, tar only operates on archives with a label matching the pattern specified in name.
—volno-file=file Used in conjunction with «—multi-volume«, tar will keep track of which volume of a multi-volume archive it’s working on in file file.
-w, —interactive, —confirmation Ask for confirmation for every action.
-W, —verify Attempt to verify the archive after writing it.
—warning=keyword Control display of the warning messages identified by keyword. If keyword starts with the prefix «no-«, such messages are suppressed. Otherwise, they are enabled.

Multiple «—warning» specifications may be used.

There are keywords for various warning messages available in tar. The two global keywords are:

all Enable all warning messages. This is the default.
none Disable all warning messages.
—wildcards Use wildcards.
—wildcards-match-slash When this option is specified, a wildcard like «*» in the pattern can match a «/» in the name. Otherwise, «/» is matched only by «/«. This is the default when tar is excluding files.
—no-wildcards-match-slash «/» cannot be matched by a wildcard, only by «/«.
—no-wildcards Wildcards are not permitted. File names may only be matched verbatim.
-X, —exclude-from=file Like —exclude, but excludes files matching the patterns listed in the file file.
-z, —gzip, —gunzip This option tells tar to read or write archives through gzip, allowing tar to directly operate on several kinds of compressed archives transparently. This option should be used, for example, when operating on files with the extension .tar.gz.
-Z, —compress, —uncompress tar uses the compress program when operating on files.

Environment

The following environment variables affect the operation of tar:

SIMPLE_BACKUP_SUFFIX File name suffix to use when backing up files, if —suffix is not specified. The default backup suffix is «~«.
TAR_OPTIONS Any options specified in this variable will be prepended to options specified to tar on the command line.
TAPE The archiving tape or file to use if —file is not specified. If this variable is not defined, and no —file is specified, tar uses standard input and standard output instead.

Examples

tar -cf archive.tar file1 file2

Create archive archive.tar containing files file1 and file2. Here, the c tells tar you will be creating an archive; the f tells tar that the next option (here it’s archive.tar) will be the name of the archive it creates. file1 and file2, the final arguments, are the files to be archived.

tar -tvf archive.tar

List the files in the archive archive.tar verbosely. Here, the t tells tar to list the contents of an archive; v tells tar to operate verbosely; and f indicates that the next argument will be the name of the archive file to operate on.

tar -xf archive.tar

Extract the files from archive archive.tar. x tells tar to extract files from an archive; f tells tar that the next argument will be the name of the archive to operate on.

tar -xzvf archive.tar.gz

Extract the files from gzipped archive archive.tar.gz verbosely. Here, the z tells tar that the archive will be compressed with gzip.

tar -cf archive.tar mydir/

Creates an archive of the directory mydir.

tar -czf archive.tar.gz mydir/

Creates an gzip-compressed archive of the directory mydir.

tar -zxvf myfile.tar.gz

Extract the contents of the myfile.tar.gz into the current directory.

tar -xvf archive.tar documents/work/budget.doc

Extract only the file documents/work/budget.doc from the archive archive.tar. Produce verbose output.

tar -xvf archive.tar documents/work/

Extract only the directory documents/work/, and any files it contains, from the archive archive.tar. Produce verbose output.

tar -xvf archive.tar --wildcards '*.doc'

Extract only files with the extension .doc from the archive archive.tar. The —wildcards option tells tar to interpret wildcards in the name of the files to be extracted; the file name (*.doc) is enclosed in single-quotes to protect the wildcard (*) from being expanded incorrectly by the shell.

tar -rvf archive.tar documents/work/budget.doc

Add the file documents/work/budget.doc to the existing archive archive.tar. The r option is the same as the long option —append.

tar -uvf archive.tar documents/work/budget.doc

Add the file documents/work/budget.doc to the archive archive.tar only if it’s newer than the version already in the archive (or does not yet exist in the archive). Here, u is the same as the long option —update.

tar -cf - documents/work/ | wc -c

Estimate the file size of an archive of the directory documents/work, but do not create the file. Here, the archive file is specified as a dash (««), which tells tar to send its archived output to the standard output rather than a file on disk. This output is then piped to the wc command, which reports how many bytes (-c) were in the input it received.

tar -czf DogPhotos.tar.gz --exclude='kitty.jpg' MyPetPhotos

Create DogPhotos.tar.gz of all files contained in the MyPetPhotos without the kitty.jpg photo.

tar tf hope.tar.gz | grep myfile.txt

Search the hope.tar.gz file for the file myfile.txt and list the full path of the file. The returned results would resemble the line shown below.

computerhopehope/homedir/public_html/data/myfile.txt

tar -zxvf hope.tar.gz computerhopehope/homedir/public_html/data/myfile.txt

In the above example, the tar command would extract the one file myfile.txt from the hope.tar.gz. The full path to this file was determined using the example shown earlier.

ar — Create, modify, and extract files from archives.
basename — Strip directory information and suffixes from file names.
cd — Change the working directory.
chown — Change the ownership of files or directories.
cpio — Copy files to or from archives.
dirname — Strip the file name from a pathname, leaving only the directory component.
gzip —Create, modify, list the contents of, and extract files from GNU zip archives.
ls — List the contents of a directory or directories.
mt — Control magnetic tapes.
zcat — Print the uncompressed contents of compressed files.

tar — Man Page

an archiving utility

Examples (TL;DR)

  • [c]reate an archive and write it to a [f]ile: tar cf path/to/target.tar path/to/file1 path/to/file2 ...
  • [c]reate a g[z]ipped archive and write it to a [f]ile: tar czf path/to/target.tar.gz path/to/file1 path/to/file2 ...
  • [c]reate a g[z]ipped archive from a directory using relative paths: tar czf path/to/target.tar.gz --directory=path/to/directory .
  • E[x]tract a (compressed) archive [f]ile into the current directory [v]erbosely: tar xvf path/to/source.tar[.gz|.bz2|.xz]
  • E[x]tract a (compressed) archive [f]ile into the target directory: tar xf path/to/source.tar[.gz|.bz2|.xz] --directory=path/to/directory
  • [c]reate a compressed archive and write it to a [f]ile, using [a]rchive suffix to determine the compression program: tar caf path/to/target.tar.xz path/to/file1 path/to/file2 ...
  • Lis[t] the contents of a tar [f]ile [v]erbosely: tar tvf path/to/source.tar
  • E[x]tract files matching a pattern from an archive [f]ile: tar xf path/to/source.tar --wildcards "*.html"

tldr.sh

Synopsis

Traditional usage

tar {A|c|d|r|t|u|x}[GnSkUWOmpsMBiajJzZhPlRvwo] [ARG…]

UNIX-style usage

tar -A [Options] -f ARCHIVE ARCHIVE

tar -c [-f ARCHIVE] [Options] [FILE…]

tar -d [-f ARCHIVE] [Options] [FILE…]

tar -r [-f ARCHIVE] [Options] [FILE…]

tar -t [-f ARCHIVE] [Options] [MEMBER…]

tar -u [-f ARCHIVE] [Options] [FILE…]

tar -x [-f ARCHIVE] [Options] [MEMBER…]

GNU-style usage

tar {—catenate|—concatenate} [Options] —file ARCHIVE ARCHIVE

tar —create [—file ARCHIVE] [Options] [FILE…]

tar {—diff|—compare} [—file ARCHIVE] [Options] [FILE…]

tar —delete [—file ARCHIVE] [Options] [MEMBER…]

tar —append [—file ARCHIVE] [Options] [FILE…]

tar —list [—file ARCHIVE] [Options] [MEMBER…]

tar —test-label [—file ARCHIVE] [Options] [LABEL…]

tar —update [—file ARCHIVE] [Options] [FILE…]

tar {—extract|—get} [—file ARCHIVE] [Options] [MEMBER…]

Note

This manpage is a short description of GNU tar.  For a detailed discussion, including examples and usage recommendations, refer to the GNU Tar Manual available in texinfo format.  If the info reader and the tar documentation are properly installed on your system, the command

info tar

should give you access to the complete manual.

You can also view the manual using the info mode in emacs(1), or find it in various formats online at

If any discrepancies occur between this manpage and the GNU Tar Manual, the later shall be considered the authoritative source.

Description

GNU tar is an archiving program designed to store multiple files in a single file (an archive), and to manipulate such archives.  The archive can be either a regular file or a device (e.g. a tape drive, hence the name of the program, which stands for tape archiver), which can be located either on the local or on a remote machine.

Option styles

Options to GNU tar can be given in three different styles. In traditional style, the first argument is a cluster of option letters and all subsequent arguments supply arguments to those options that require them.  The arguments are read in the same order as the option letters.  Any command line words that remain after all options have been processed are treated as non-option arguments: file or archive member names.

For example, the c option requires creating the archive, the v option requests the verbose operation, and the f option takes an argument that sets the name of the archive to operate upon. The following command, written in the traditional style, instructs tar to store all files from the directory /etc into the archive file etc.tar, verbosely listing the files being archived:

tar cfv etc.tar /etc

In UNIX or short-option style, each option letter is prefixed with a single dash, as in other command line utilities.  If an option takes an argument, the argument follows it, either as a separate command line word, or immediately following the option.  However, if the option takes an optional argument, the argument must follow the option letter without any intervening whitespace, as in -g/tmp/snar.db.

Any number of options not taking arguments can be clustered together after a single dash, e.g. -vkp.  An option that takes an argument (whether mandatory or optional) can appear at the end of such a cluster, e.g. -vkpf a.tar.

The example command above written in the short-option style could look like:

tar -cvf etc.tar /etc

or

tar -c -v -f etc.tar /etc

In GNU or long-option style, each option begins with two dashes and has a meaningful name, consisting of lower-case letters and dashes.  When used, the long option can be abbreviated to its initial letters, provided that this does not create ambiguity.  Arguments to long options are supplied either as a separate command line word, immediately following the option, or separated from the option by an equals sign with no intervening whitespace.  Optional arguments must always use the latter method.

Here are several ways of writing the example command in this style:

tar --create --file etc.tar --verbose /etc

or (abbreviating some options):

tar --cre --file=etc.tar --verb /etc

The options in all three styles can be intermixed, although doing so with old options is not encouraged.

Operation mode

The options listed in the table below tell GNU tar what operation it is to perform.  Exactly one of them must be given. The meaning of non-option arguments depends on the operation mode requested.

-A,  —catenate,  —concatenate

Append archives to the end of another archive.  The arguments are treated as the names of archives to append.  All archives must be of the same format as the archive they are appended to, otherwise the resulting archive might be unusable with non-GNU implementations of tar.  Notice also that when more than one archive is given, the members from archives other than the first one will be accessible in the resulting archive only when using the -i (—ignore-zeros) option.

Compressed archives cannot be concatenated.

-c,  —create

Create a new archive.  Arguments supply the names of the files to be archived.  Directories are archived recursively, unless the —no-recursion option is given.

-d,  —diff,  —compare

Find differences between archive and file system.  The arguments are optional and specify archive members to compare.  If not given, the current working directory is assumed.

—delete

Delete from the archive.  The arguments supply names of the archive members to be removed.  At least one argument must be given.

This option does not operate on compressed archives.  There is no short option equivalent.

-r,  —append

Append files to the end of an archive.  Arguments have the same meaning as for -c (—create).

-t,  —list

List the contents of an archive.  Arguments are optional.  When given, they specify the names of the members to list.

—test-label

Test the archive volume label and exit.  When used without arguments, it prints the volume label (if any) and exits with status 0. When one or more command line arguments are given. tar compares the volume label with each argument.  It exits with code 0 if a match is found, and with code 1 otherwise.  No output is displayed, unless used together with the -v (—verbose) option.

There is no short option equivalent for this option.

-u,  —update

Append files which are newer than the corresponding copy in the archive.  Arguments have the same meaning as with the -c and -r options.  Notice, that newer files don’t replace their old archive copies, but instead are appended to the end of archive. The resulting archive can thus contain several members of the same name, corresponding to various versions of the same file.

-x,  —extract,  —get

Extract files from an archive.  Arguments are optional.  When given, they specify names of the archive members to be extracted.

—show-defaults

Show built-in defaults for various tar options and exit.

-?,  —help

Display a short option summary and exit.

—usage

Display a list of available options and exit.

—version

Print program version and copyright information and exit.

Options

Operation modifiers

—check-device

Check device numbers when creating incremental archives (default).

-g,  —listed-incremental=FILE

Handle new GNU-format incremental backups.  FILE is the name of a snapshot file, where tar stores additional information which is used to decide which files changed since the previous incremental dump and, consequently, must be dumped again.  If FILE does not exist when creating an archive, it will be created and all files will be added to the resulting archive (the level 0 dump).  To create incremental archives of non-zero level N, you need a copy of the snapshot file created for level N-1, and use it as FILE.

When listing or extracting, the actual content of FILE is not inspected, it is needed only due to syntactical requirements.  It is therefore common practice to use /dev/null in its place.

—hole-detection=METHOD

Use METHOD to detect holes in sparse files.  This option implies —sparse.  Valid values for METHOD are seek and raw.  Default is seek with fallback to raw when not applicable.

-G,  —incremental

Handle old GNU-format incremental backups.

—ignore-failed-read

Do not exit with nonzero on unreadable files.

—level=NUMBER

Set dump level for a created listed-incremental archive.  Currently only —level=0 is meaningful: it instructs tar to truncate the snapshot file before dumping, thereby forcing a level 0 dump.

-n,  —seek

Assume the archive is seekable.  Normally tar determines automatically whether the archive can be seeked or not.  This option is intended for use in cases when such recognition fails.  It takes effect only if the archive is open for reading (e.g. with —list or —extract options).

—no-check-device

Do not check device numbers when creating incremental archives.

—no-seek

Assume the archive is not seekable.

—occurrence[=N]

Process only the Nth occurrence of each file in the archive.  This option is valid only when used with one of the following subcommands: —delete, —diff, —extract or —list and when a list of files is given either on the command line or via the -T option.  The default N is 1.

—restrict

Disable the use of some potentially harmful options.

—sparse-version=MAJOR[.MINOR]

Set which version of the sparse format to use. This option implies —sparse. Valid argument values are 0.0, 0.1, and 1.0. For a detailed discussion of sparse formats, refer to the GNU Tar Manual, appendix D, «Sparse Formats«.  Using the info reader, it can be accessed running the following command: info tar ‘Sparse Formats’.

-S,  —sparse

Handle sparse files efficiently.  Some files in the file system may have segments which were actually never written (quite often these are database files created by such systems as DBM).  When given this option, tar attempts to determine if the file is sparse prior to archiving it, and if so, to reduce the resulting archive size by not dumping empty parts of the file.

Overwrite control

These options control tar actions when extracting a file over an existing copy on disk.

-k,  —keep-old-files

Don’t replace existing files when extracting.

—keep-newer-files

Don’t replace existing files that are newer than their archive copies.

—keep-directory-symlink

Don’t replace existing symlinks to directories when extracting.

—no-overwrite-dir

Preserve metadata of existing directories.

—one-top-level[=DIR]

Extract all files into DIR, or, if used without argument, into a subdirectory named by the base name of the archive (minus standard compression suffixes recognizable by —auto-compress).

—overwrite

Overwrite existing files when extracting.

—overwrite-dir

Overwrite metadata of existing directories when extracting (default).

—recursive-unlink

Recursively remove all files in the directory prior to extracting it.

—remove-files

Remove files from disk after adding them to the archive.

—skip-old-files

Don’t replace existing files when extracting, silently skip over them.

-U,  —unlink-first

Remove each file prior to extracting over it.

-W,  —verify

Verify the archive after writing it.

Output stream selection

—ignore-command-error

Ignore subprocess exit codes.

—no-ignore-command-error

Treat non-zero exit codes of children as error (default).

-O,  —to-stdout

Extract files to standard output.

—to-command=COMMAND

Pipe extracted files to COMMAND.  The argument is the pathname of an external program, optionally with command line arguments.  The program will be invoked and the contents of the file being extracted supplied to it on its standard input.  Additional data will be supplied via the following environment variables:

TAR_FILETYPE

Type of the file. It is a single letter with the following meaning:

	f	Regular file
	d	Directory
	l	Symbolic link
	h	Hard link
	b	Block device
	c	Character device

Currently only regular files are supported.

TAR_MODE

File mode, an octal number.

TAR_FILENAME

The name of the file.

TAR_REALNAME

Name of the file as stored in the archive.

TAR_UNAME

Name of the file owner.

TAR_GNAME

Name of the file owner group.

TAR_ATIME

Time of last access. It is a decimal number, representing seconds since the Epoch.  If the archive provides times with nanosecond precision, the nanoseconds are appended to the timestamp after a decimal point.

TAR_MTIME

Time of last modification.

TAR_CTIME

Time of last status change.

TAR_SIZE

Size of the file.

TAR_UID

UID of the file owner.

TAR_GID

GID of the file owner.

Additionally, the following variables contain information about tar operation mode and the archive being processed:

TAR_VERSION

GNU tar version number.

TAR_ARCHIVE

The name of the archive tar is processing.

TAR_BLOCKING_FACTOR

Current blocking factor, i.e. number of 512-byte blocks in a record.

TAR_VOLUME

Ordinal number of the volume tar is processing (set if reading a multi-volume archive).

TAR_FORMAT

Format of the archive being processed.  One of: gnu, oldgnu, posix, ustar, v7.

TAR_SUBCOMMAND

A short option (with a leading dash) describing the operation tar is executing.

Handling of file attributes

—atime-preserve[=METHOD]

Preserve access times on dumped files, either by restoring the times after reading (METHOD=replace, this is the default) or by not setting the times in the first place (METHOD=system).

—delay-directory-restore

Delay setting modification times and permissions of extracted directories until the end of extraction.  Use this option when extracting from an archive which has unusual member ordering.

—group=NAME[:GID]

Force NAME as group for added files.  If GID is not supplied, NAME can be either a user name or numeric GID.  In this case the missing part (GID or name) will be inferred from the current host’s group database.

When used with —group-map=FILE, affects only those files whose owner group is not listed in FILE.

—group-map=FILE

Read group translation map from FILE.  Empty lines are ignored. Comments are introduced with # sign and extend to the end of line. Each non-empty line in FILE defines translation for a single group.  It must consist of two fields, delimited by any amount of whitespace:

OLDGRP NEWGRP[:NEWGID]

OLDGRP is either a valid group name or a GID prefixed with +.  Unless NEWGID is supplied, NEWGRP must also be either a valid group name or a +GID.  Otherwise, both NEWGRP and NEWGID need not be listed in the system group database.

As a result, each input file with owner group OLDGRP will be stored in archive with owner group NEWGRP and GID NEWGID.

—mode=CHANGES

Force symbolic mode CHANGES for added files.

—mtime=DATE-OR-FILE

Set mtime for added files.  DATE-OR-FILE is either a date/time in almost arbitrary format, or the name of an existing file.  In the latter case the mtime of that file will be used.

-m,  —touch

Don’t extract file modified time.

—no-delay-directory-restore

Cancel the effect of the prior —delay-directory-restore option.

—no-same-owner

Extract files as yourself (default for ordinary users).

—no-same-permissions

Apply the user’s umask when extracting permissions from the archive (default for ordinary users).

—numeric-owner

Always use numbers for user/group names.

—owner=NAME[:UID]

Force NAME as owner for added files.  If UID is not supplied, NAME can be either a user name or numeric UID.  In this case the missing part (UID or name) will be inferred from the current host’s user database.

When used with —owner-map=FILE, affects only those files whose owner is not listed in FILE.

—owner-map=FILE

Read owner translation map from FILE.  Empty lines are ignored. Comments are introduced with # sign and extend to the end of line. Each non-empty line in FILE defines translation for a single UID.  It must consist of two fields, delimited by any amount of whitespace:

OLDUSR NEWUSR[:NEWUID]

OLDUSR is either a valid user name or a UID prefixed with +.  Unless NEWUID is supplied, NEWUSR must also be either a valid user name or a +UID.  Otherwise, both NEWUSR and NEWUID need not be listed in the system user database.

As a result, each input file owned by OLDUSR will be stored in archive with owner name NEWUSR and UID NEWUID.

-p,  —preserve-permissions,  —same-permissions

Set permissions of extracted files to those recorded in the archive (default for superuser).

—same-owner

Try extracting files with the same ownership as exists in the archive (default for superuser).

-s,  —preserve-order,  —same-order

Tell tar that the list of file names to process is sorted in the same order as the files in the archive.

—sort=ORDER

When creating an archive, sort directory entries according to ORDER, which is one of none, name, or inode.

The default is —sort=none, which stores archive members in the same order as returned by the operating system.

Using —sort=name ensures the member ordering in the created archive is uniform and reproducible.

Using —sort=inode reduces the number of disk seeks made when creating the archive and thus can considerably speed up archivation. This sorting order is supported only if the underlying system provides the necessary information.

Extended file attributes

—acls

Enable POSIX ACLs support.

—no-acls

Disable POSIX ACLs support.

—selinux

Enable SELinux context support.

—no-selinux

Disable SELinux context support.

—xattrs

Enable extended attributes support.

—no-xattrs

Disable extended attributes support.

—xattrs-exclude=PATTERN

Specify the exclude pattern for xattr keys.  PATTERN is a globbing pattern, e.g. —xattrs-exclude=’user.*’ to include only attributes from the user namespace.

—xattrs-include=PATTERN

Specify the include pattern for xattr keys.  PATTERN is a globbing pattern.

Device selection and switching

-f,  —file=ARCHIVE

Use archive file or device ARCHIVE.  If this option is not given, tar will first examine the environment variable `TAPE’. If it is set, its value will be used as the archive name.  Otherwise, tar will assume the compiled-in default.  The default value can be inspected either using the —show-defaults option, or at the end of the tar —help output.

An archive name that has a colon in it specifies a file or device on a remote machine.  The part before the colon is taken as the machine name or IP address, and the part after it as the file or device pathname, e.g.:

--file=remotehost:/dev/sr0

An optional username can be prefixed to the hostname, placing a @ sign between them.

By default, the remote host is accessed via the rsh(1) command.  Nowadays it is common to use ssh(1) instead.  You can do so by giving the following command line option:

--rsh-command=/usr/bin/ssh

The remote machine should have the rmt(8) command installed.  If its pathname does not match tar‘s default, you can inform tar about the correct pathname using the —rmt-command option.

—force-local

Archive file is local even if it has a colon.

-F,  —info-script=COMMAND, —new-volume-script=COMMAND

Run COMMAND at the end of each tape (implies -M).  The command can include arguments.  When started, it will inherit tar‘s environment plus the following variables:

TAR_VERSION

GNU tar version number.

TAR_ARCHIVE

The name of the archive tar is processing.

TAR_BLOCKING_FACTOR

Current blocking factor, i.e. number of 512-byte blocks in a record.

TAR_VOLUME

Ordinal number of the volume tar is processing (set if reading a multi-volume archive).

TAR_FORMAT

Format of the archive being processed.  One of: gnu, oldgnu, posix, ustar, v7.

TAR_SUBCOMMAND

A short option (with a leading dash) describing the operation tar is executing.

TAR_FD

File descriptor which can be used to communicate the new volume name to tar.

If the info script fails, tar exits; otherwise, it begins writing the next volume.

-L,  —tape-length=N

Change tape after writing Nx1024 bytes.  If N is followed by a size suffix (see the subsection Size suffixes below), the suffix specifies the multiplicative factor to be used instead of 1024.

This option implies -M.

-M,  —multi-volume

Create/list/extract multi-volume archive.

—rmt-command=COMMAND

Use COMMAND instead of rmt when accessing remote archives.  See the description of the -f option, above.

—rsh-command=COMMAND

Use COMMAND instead of rsh when accessing remote archives.  See the description of the -f option, above.

—volno-file=FILE

When this option is used in conjunction with —multi-volume, tar will keep track of which volume of a multi-volume archive it is working in FILE.

Device blocking

-b,  —blocking-factor=BLOCKS

Set record size to BLOCKSx512 bytes.

-B,  —read-full-records

When listing or extracting, accept incomplete input records after end-of-file marker.

-i,  —ignore-zeros

Ignore zeroed blocks in archive.  Normally two consecutive 512-blocks filled with zeroes mean EOF and tar stops reading after encountering them.  This option instructs it to read further and is useful when reading archives created with the -A option.

—record-size=NUMBER

Set record size.  NUMBER is the number of bytes per record.  It must be multiple of 512.  It can can be suffixed with a size suffix, e.g. —record-size=10K, for 10 Kilobytes.  See the subsection Size suffixes, for a list of valid suffixes.

Archive format selection

-H,  —format=FORMAT

Create archive of the given format.  Valid formats are:

gnu

GNU tar 1.13.x format

oldgnu

GNU format as per tar <= 1.12.

pax, posix

POSIX 1003.1-2001 (pax) format.

ustar

POSIX 1003.1-1988 (ustar) format.

v7

Old V7 tar format.

—old-archive,  —portability

Same as —format=v7.

—pax-option=keyword[[:]=value][,keyword[[:]=value]]…

Control pax keywords when creating PAX archives (-H pax).  This option is equivalent to the -o option of the pax(1) utility.

—posix

Same as —format=posix.

-V,  —label=TEXT

Create archive with volume name TEXT.  If listing or extracting, use TEXT as a globbing pattern for volume name.

Compression options

-a,  —auto-compress

Use archive suffix to determine the compression program.

-I,  —use-compress-program=COMMAND

Filter data through COMMAND.  It must accept the -d option, for decompression.  The argument can contain command line options.

-j,  —bzip2

Filter the archive through bzip2(1).

-J,  —xz

Filter the archive through xz(1).

—lzip

Filter the archive through lzip(1).

—lzma

Filter the archive through lzma(1).

—lzop

Filter the archive through lzop(1).

—no-auto-compress

Do not use archive suffix to determine the compression program.

-z,  —gzip,  —gunzip,  —ungzip

Filter the archive through gzip(1).

-Z,  —compress,  —uncompress

Filter the archive through compress(1).

—zstd

Filter the archive through zstd(1).

Local file selection

—add-file=FILE

Add FILE to the archive (useful if its name starts with a dash).

—backup[=CONTROL]

Backup before removal.  The CONTROL argument, if supplied, controls the backup policy.  Its valid values are:

none, off

Never make backups.

t, numbered

Make numbered backups.

nil, existing

Make numbered backups if numbered backups exist, simple backups otherwise.

never, simple

Always make simple backups

If CONTROL is not given, the value is taken from the VERSION_CONTROL environment variable.  If it is not set, existing is assumed.

-C,  —directory=DIR

Change to DIR before performing any operations.  This option is order-sensitive, i.e. it affects all options that follow.

—exclude=PATTERN

Exclude files matching PATTERN, a glob(3)-style wildcard pattern.

—exclude-backups

Exclude backup and lock files.

—exclude-caches

Exclude contents of directories containing file CACHEDIR.TAG, except for the tag file itself.

—exclude-caches-all

Exclude directories containing file CACHEDIR.TAG and the file itself.

—exclude-caches-under

Exclude everything under directories containing CACHEDIR.TAG

—exclude-ignore=FILE

Before dumping a directory, see if it contains FILE. If so, read exclusion patterns from this file.  The patterns affect only the directory itself.

—exclude-ignore-recursive=FILE

Same as —exclude-ignore, except that patterns from FILE affect both the directory and all its subdirectories.

—exclude-tag=FILE

Exclude contents of directories containing FILE, except for FILE itself.

—exclude-tag-all=FILE

Exclude directories containing FILE.

—exclude-tag-under=FILE

Exclude everything under directories containing FILE.

—exclude-vcs

Exclude version control system directories.

—exclude-vcs-ignores

Exclude files that match patterns read from VCS-specific ignore files.  Supported files are: .cvsignore, .gitignore, .bzrignore, and .hgignore.

-h,  —dereference

Follow symlinks; archive and dump the files they point to.

—hard-dereference

Follow hard links; archive and dump the files they refer to.

-K,  —starting-file=MEMBER

Begin at the given member in the archive.

—newer-mtime=DATE

Work on files whose data changed after the DATE.  If DATE starts with / or . it is taken to be a file name; the mtime of that file is used as the date.

—no-null

Disable the effect of the previous —null option.

—no-recursion

Avoid descending automatically in directories.

—no-unquote

Do not unquote input file or member names.

—no-verbatim-files-from

Treat each line read from a file list as if it were supplied in the command line.  I.e., leading and trailing whitespace is removed and, if the resulting string begins with a dash, it is treated as tar command line option.

This is the default behavior.  The —no-verbatim-files-from option is provided as a way to restore it after —verbatim-files-from option.

This option is positional: it affects all —files-from options that occur after it in, until —verbatim-files-from option or end of line, whichever occurs first.

It is implied by the —no-null option.

—null

Instruct subsequent -T options to read null-terminated names verbatim (disables special handling of names that start with a dash).

See also —verbatim-files-from.

-N,  —newer=DATE, —after-date=DATE

Only store files newer than DATE.  If DATE starts with / or . it is taken to be a file name; the mtime of that file is used as the date.

—one-file-system

Stay in local file system when creating archive.

-P,  —absolute-names

Don’t strip leading slashes from file names when creating archives.

—recursion

Recurse into directories (default).

—suffix=STRING

Backup before removal, override usual suffix.  Default suffix is ~, unless overridden by environment variable SIMPLE_BACKUP_SUFFIX.

-T,  —files-from=FILE

Get names to extract or create from FILE.

Unless specified otherwise, the FILE must contain a list of names separated by ASCII LF (i.e. one name per line).  The names read are handled the same way as command line arguments.  They undergo quote removal and word splitting, and any string that starts with a is handled as tar command line option.

If this behavior is undesirable, it can be turned off using the —verbatim-files-from option.

The —null option instructs tar that the names in FILE are separated by ASCII NUL character, instead of LF.  It is useful if the list is generated by find(1) -print0 predicate.

—unquote

Unquote file or member names (default).

—verbatim-files-from

Treat each line obtained from a file list as a file name, even if it starts with a dash.  File lists are supplied with the —files-from (-T) option.  The default behavior is to handle names supplied in file lists as if they were typed in the command line, i.e. any names starting with a dash are treated as tar options.  The —verbatim-files-from option disables this behavior.

This option affects all —files-from options that occur after it in the command line.  Its effect is reverted by the —no-verbatim-files-from option.

This option is implied by the —null option.

See also —add-file.

-X,  —exclude-from=FILE

Exclude files matching patterns listed in FILE.

File name transformations

—strip-components=NUMBER

Strip NUMBER leading components from file names on extraction.

—transform=EXPRESSION, —xform=EXPRESSION

Use sed replace EXPRESSION to transform file names.

File name matching options

These options affect both exclude and include patterns.

—anchored

Patterns match file name start.

—ignore-case

Ignore case.

—no-anchored

Patterns match after any / (default for exclusion).

—no-ignore-case

Case sensitive matching (default).

—no-wildcards

Verbatim string matching.

—no-wildcards-match-slash

Wildcards do not match /.

—wildcards

Use wildcards (default for exclusion).

—wildcards-match-slash

Wildcards match / (default for exclusion).

Informative output

—checkpoint[=N]

Display progress messages every Nth record (default 10).

—checkpoint-action=ACTION

Run ACTION on each checkpoint.

—clamp-mtime

Only set time when the file is more recent than what was given with —mtime.

—full-time

Print file time to its full resolution.

—index-file=FILE

Send verbose output to FILE.

-l,  —check-links

Print a message if not all links are dumped.

—no-quote-chars=STRING

Disable quoting for characters from STRING.

—quote-chars=STRING

Additionally quote characters from STRING.

—quoting-style=STYLE

Set quoting style for file and member names.  Valid values for STYLE are literal, shell, shell-always, c, c-maybe, escape, locale, clocale.

-R,  —block-number

Show block number within archive with each message.

—show-omitted-dirs

When listing or extracting, list each directory that does not match search criteria.

—show-transformed-names,  —show-stored-names

Show file or archive names after transformation by —strip and —transform options.

—totals[=SIGNAL]

Print total bytes after processing the archive.  If SIGNAL is given, print total bytes when this signal is delivered.  Allowed signals are: SIGHUP, SIGQUIT, SIGINT, SIGUSR1, and SIGUSR2. The SIG prefix can be omitted.

—utc

Print file modification times in UTC.

-v,  —verbose

Verbosely list files processed.  Each instance of this option on the command line increases the verbosity level by one.  The maximum verbosity level is 3.  For a detailed discussion of how various verbosity levels affect tar’s output, please refer to GNU Tar Manual, subsection 2.5.2 «The ‘—verbose’ Option«.

—warning=KEYWORD

Enable or disable warning messages identified by KEYWORD.  The messages are suppressed if KEYWORD is prefixed with no- and enabled otherwise.

Multiple —warning options accumulate.

Keywords controlling general tar operation:

all

Enable all warning messages.  This is the default.

none

Disable all warning messages.

filename-with-nuls

«%s: file name read contains nul character»

alone-zero-block

«A lone zero block at %s»

Keywords applicable for tar —create:

cachedir

«%s: contains a cache directory tag %s; %s»

file-shrank

«%s: File shrank by %s bytes; padding with zeros»

xdev

«%s: file is on a different filesystem; not dumped»

file-ignored

«%s: Unknown file type; file ignored»
«%s: socket ignored»
«%s: door ignored»

file-unchanged

«%s: file is unchanged; not dumped»

ignore-archive

«%s: archive cannot contain itself; not dumped»

file-removed

«%s: File removed before we read it»

file-changed

«%s: file changed as we read it»

failed-read

Suppresses warnings about unreadable files or directories. This keyword applies only if used together with the —ignore-failed-read option.

Keywords applicable for tar —extract:

existing-file

«%s: skipping existing file»

timestamp

«%s: implausibly old time stamp %s»
«%s: time stamp %s is %s s in the future»

contiguous-cast

«Extracting contiguous files as regular files»

symlink-cast

«Attempting extraction of symbolic links as hard links»

unknown-cast

«%s: Unknown file type ‘%c’, extracted as normal file»

ignore-newer

«Current %s is newer or same age»

unknown-keyword

«Ignoring unknown extended header keyword ‘%s'»

decompress-program

Controls verbose description of failures occurring when trying to run alternative decompressor programs.  This warning is disabled by default (unless —verbose is used).  A common example of what you can get when using this warning is:

$ tar --warning=decompress-program -x -f archive.Z
tar (child): cannot run compress: No such file or directory
tar (child): trying gzip

This means that tar first tried to decompress archive.Z using compress, and, when that failed, switched to gzip.

record-size

«Record size = %lu blocks»

Keywords controlling incremental extraction:

rename-directory

«%s: Directory has been renamed from %s»
«%s: Directory has been renamed»

new-directory

«%s: Directory is new»

xdev

«%s: directory is on a different device: not purging»

bad-dumpdir

«Malformed dumpdir: ‘X’ never used»

-w,  —interactive,  —confirmation

Ask for confirmation for every action.

Compatibility options

-o

When creating, same as —old-archive.  When extracting, same as —no-same-owner.

Size suffixes

	Suffix	Units	Byte Equivalent
	b	Blocks	SIZE x 512
	B	Kilobytes	SIZE x 1024
	c	Bytes	SIZE
	G	Gigabytes	SIZE x 1024^3
	K	Kilobytes	SIZE x 1024
	k	Kilobytes	SIZE x 1024
	M	Megabytes	SIZE x 1024^2
	P	Petabytes	SIZE x 1024^5
	T	Terabytes	SIZE x 1024^4
	w	Words	SIZE x 2

Return Value

Tar’s exit code indicates whether it was able to successfully perform the requested operation, and if not, what kind of error occurred.

0

Successful termination.

1

Some files differ. If tar was invoked with the —compare (—diff, -d) command line option, this means that some files in the archive differ from their disk counterparts.  If tar was given one of the —create, —append or —update options, this exit code means that some files were changed while being archived and so the resulting archive does not contain the exact copy of the file set.

2

Fatal error. This means that some fatal, unrecoverable error occurred.

If a subprocess that had been invoked by tar exited with a nonzero exit code, tar itself exits with that code as well.  This can happen, for example, if a compression option (e.g. -z) was used and the external compressor program failed.  Another example is rmt failure during backup to a remote device.

See Also

bzip2(1), compress(1), gzip(1), lzma(1), lzop(1), rmt(8), symlink(7), xz(1), zstd(1).

Complete tar manual: run info tar or use emacs(1) info mode to read it.

Online copies of GNU tar documentation in various formats can be found at:

https://www.gnu.org/software/tar/manual

Bug Reports

Report bugs to <bug-tar@gnu.org>.

Copyright

Copyright © 2023 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law.

Referenced By

ambsdtar(8), amgtar(8), archivemount(1), archive_read(3), archive_read_add_passphrase(3), archive_read_data(3), archive_read_disk(3), archive_read_extract(3), archive_read_format(3), archive_read_header(3), archive_read_new(3), archive_read_open(3), archive_read_set_options(3), archive_write(3), archive_write_blocksize(3), archive_write_data(3), archive_write_disk(3), archive_write_filter(3), archive_write_finish_entry(3), archive_write_format(3), archive_write_free(3), archive_write_header(3), archive_write_new(3), archive_write_open(3), archive_write_set_options(3), archive_write_set_passphrase(3), arlatex(1), attr(1), bsdcpio(1), bsdtar(1), buffer(1), ch-convert(1), cimreparchive(8), containers-transports(5), cpdup(1), ctanify(1), cupsd-helper(8), dlb(6), dpkg-deb(1), dpkg-source(1), file(1), fimgs(1), fpsync(1), ftnchek(1), ftp(1), funzip(1), genisoimage(1), getarg(3), gpgtar(1), gpg-zip1(1), groff_man_style(7), gsf(1), guestfs(3), libarchive(3), libarchive-formats(5), lumina-archiver(1), lzop(1), machinectl(1), nbdkit-tar-filter(1), nomarch(1), ntfsclone(8), nulib2(1), opax(1), perl5140delta(1), ptar(1), ptardiff(1), pycdlib-genisoimage(1), rsync(1), scpio(1), shtool-tarball(1), smbclient(1), smbtar(1), snobol4io(1), st(4), star(1), star(5), sudoers(5), suffixes(7), symlink(7), tar(5), tnftp(1), ttcp(1), xz(1), zip(1).

The man page gtar(1) is an alias of tar(1).

July 11, 2022 GNU TAR Manual

Понравилась статья? Поделить с друзьями:
  • Tap2go ошибка авторизации 11
  • Taskmgr exe ошибка при выполнении приложения сервера
  • Tar short read ошибка
  • Tasklist ошибка сервер rpc недоступен
  • Tap2go ошибка небезопасная среда