Open tar linux. Linux backup - tar command

tar is the most common archiver used on Linux systems. By itself, tar is not an archiver in the usual sense of the word, because it does not use compression on its own. At the same time, many archivers (for example, Gzip or bzip2) cannot compress multiple files, but only work with one file or input stream. Therefore, most often these programs are used together. tar creates an uncompressed archive into which the selected files and directories are placed, while retaining some of their attributes (such as permissions). The resulting *.tar file is then compressed with an archiver such as gzip . This is why archives usually have the extension .tar.gz or .tar.bz2 (for gzip and bzip2 archivers respectively)

Usage

tar is launched with the obligatory indication of one of the main actions, the most common of which is the creation and unpacking of archives, then other parameters are set depending on the specific operation.

Creating an archive

To create an archive, you need to tell tar the appropriate action, which is done using the -c switch. In addition, the -f option is required to package content into a file. Next, we first specify the name of the future archive, and then the files that we want to pack.

Tar -cf txt.tar *.txt

This command will pack all files with a .txt extension into a txt.tar archive. This is how a simple archive without compression is created. To use compression, you don't need to run anything else, just tell tar which archiver to compress the archive with. For the two most popular archivers gzip and bzip2 the keys are -z and -j respectively.

Tar -cvzf files.tar.gz ~/files

will pack the ~/files folder with all its contents into a gzip-compressed archive.

Tar -cvjf files.tar.bz2 ~/files

will create a similar archive using bzip2 compression.

The -v switch turns on the output of a list of packed files during operation. Unfortunately, tar does not provide more advanced progress indications (such as indicating the degree of completion as a percentage). To do this, use graphical archivers (for example, Xarchiver) or use the tools of a file manager.

In addition to gzip and bzip2, you can use, for example, lzma (-lzma switch) or xz (-J switch), while the corresponding archiver must be installed on the system.

Unpacking the archive

The "unpacking" action is set using the -x switch. And here again the -f switch is required to specify the name of the archive file. We will also add the -v switch to visually display the progress of the process.

Tar -xvf /path/to/archive.tar.bz2

will extract the contents of the archive to the current folder. An alternative unpacking location can be specified using the -C switch:

Tar -xvf archive.tar.bz2 -C /path/to/folder

Viewing the contents of an archive

To view the contents of the archive, use the following command:

Tar -tf archive.tar.gz

It will display a simple list of files and directories in the archive. If you add the -v switch, a detailed list will be displayed indicating the size, access rights and other parameters (just like with ls -l)

Other features

tar provides many useful features. For example, you can specify files and directories that will not be included in the archive, add files to an existing archive, take a list of objects to pack from text file and much more. In all the variety of options, as always, it will help to understand

man tar tar --help

A simple backup scheme is to save everything once, and then back up everything that has changed from the previous copy. The first copy is calledfull (full backup) , subsequent incremental (incremental backups) . Full copy often does not fit entirely on tape (or diskette). Restoring from incremental backups can take many times more work than from the full. Recovery can be optimized so that you always back up everything from the previous full copy; this way requires a bit more work, but there will never be a need to restore more than a full and one incremental copy.

If you want to make copies daily and have six tapes, you could use tape 1 for the first full backup (say Friday) and tapes 2 through 5 for incremental backups (Monday-Thursday). Then you make a new full copy on tape 6 (second Friday), and start making incremental copies again on tapes 2-5. You don't want to overwrite tape 1 until you have a new full copy so that nothing bad happens while you make a new full copy. After you have made a full backup on tape 6, you can store tape 1 somewhere else in case your other backup tapes are destroyed. When you need to make the next full copy, you select and use tape 1.

If you have more than six tapes, you can use the extra space for full copies. Every time you make a full copy, you use the oldest tape. This way you can have complete copies of the previous few weeks, which is good if you want to find an old, now deleted file, or an old version of a file.

Backup using tar

A full copy can easily be made by the commandtar :

# tar --create --file /dev/ftape /usr/src

The example above uses the GNU versiontar and long option names. Traditional versiontar accepts only a single character as a parameter. The GNU version can also handle copies that don't fit on one tape or floppy disk, and very long paths; not all traditional versions can do this. Linux only uses GNUtar .

If your copy does not fit on one tape, you must use the option--multi-volume (-M ):

# tar -cMf /dev/fd0H1440 /usr/src

tar: Removing leading / from absolute path names in the archive

Prepare volume #2 for /dev/fd0H1440 and hit return:

Note that you must format the floppy disks before you start copying. You can use another window or virtual terminal to execute formatting commands whentar will ask for a new diskette.

After you have made a copy, you must verify it using the option--compare (-d ):

# tar --compare --verbose -f /dev/ftape

usr/src/

usr/src/linux

....

Failure to verify the copy means that you will not notice that your copy is not working until you lose the original data.

An incremental copy can be done with the commandtar with --newer (-N ) option:

# tar --create --newer "8 Sep 1995" --file /dev/ftape /usr/src --verbose

tar: Removing leading / from absolute path names in the archive

usr/src/

usr/src/linux-1.2.10-includes/

usr/src/linux-1.2.10-includes/include/linux/modules/

usr/src/linux-1.2.10-includes/include/asm-generic/

usr/src/linux-1.2.10-includes/include/asm-i386/

usr/src/linux-1.2.10-includes/include/asm-mips/

usr/src/linux-1.2.10-includes/include/asm-alpha/

usr/src/linux-1.2.10-includes/include/asm-m68k/

usr/src/linux-1.2.10-includes/include/asm-sparc/

usr/src/patch-1.2.11.gz

Unfortunately, tar cannot detect inode change file information such as changing permissions or renaming a file. The problem is solved by using the commandfind and comparing the current state of the file system with lists of files that were previously backed up. Scripts and programs to automate this process can be found on Linux ftp servers.

Recovery using tar

Command tar with --extract (-x ) extracts files:

# tar --extract --same-permissions --verbose --file /dev/fd0H1440

usr/src/

usr/src/linux

usr/src/linux-1.2.10-includes/

usr/src/linux-1.2.10-includes/includes/

usr/src/linux-1.2.10-includes/include/linux/

...

You can also only extract specified files or directories (which include all their files and subdirectories) by listing them on the command line:

# tar xpvf /dev/fd0H1440 usr/src/linux-1.2.10-includes/include/linux/hdreg.h

usr/src/linux-1.2.10-includes/include/linux/hdreg.h

Use the option--list (-t ) if you only want to see what files are on the backup volume:

# tar --list --file /dev/fd0H1440

usr/src/

usr/src/linux

usr/src/linux-1.2.10-includes/

usr/src/linux-1.2.10-includes/includes/

usr/src/linux-1.2.10-includes/include/linux/

usr/src/linux-1.2.10-includes/include/linux/hdreg.h

usr/src/linux-1.2.10-includes/include/linux/kernel.h

...

note thattar always reads the backup volume sequentially, so for large volumes the process is quite slow. However, random access cannot be used when tape or some other serial medium is used.

tar does not process deleted files right. If you need to restore a file system from a full and incremental backup, and delete a file between backups, it will exist again after you do the restore. This can be a big problem if the file contains important data that should no longer be available.



man tar Usage: tar [OPTION...] [FILE]...
GNU `tar" is for saving files
on tape or archived on disk and
recovery individual files from
archive.

Examples:
tar -cf archive.tar foo bar # Create archive.tar from files
foo and bar.
tar -tvf archive.tar # Verbose listing
all files in the archive.tar archive.
tar -xf archive.tar # Extract all files
from archive.tar.

Main mode of operation:

A, --catenate, --concatenate concatenate tar files
to the archive
-c, --create create a new archive
-d, --diff, --compare diff between
archive and file
system
--delete remove from archive (not on
magnetic tapes!
-r, --append append files to the end
archive
-t, --list list contents
archive
--test-label test archive volume label
and exit
-u, --update add to archive only
newer files
-x, --extract, --get extract files from
archive

Modifiers:

Check-device check device numbers when
creating incremental
archives (default)
-g, --listed-incremental=FILE
additional processing
reserving a new
GNU format
-G, --incremental process incremental
reservation of the old
GNU format
--ignore-failed-read don't exit when
non-zero status for
unreadable files
-n, --seek archive search available
--no-check-device do not check device numbers when creating
incremental archives
--occurrence[=N] process only the Nth
entries for each
file in the archive. This option
valid only in combination with
one of the --delete subcommands,
--diff, --extract or --list and when
the list of files is specified either in
command line, or
via the -T option. Default
N is 1.
--sparse-version=MAJOR[.MINOR]
install version
format used
rarefaction (implies
--sparse)
-S, --sparse efficient processing
sparse files

Overwrite control:

K, --keep-old-files do not overwrite
existing files at
extraction
--keep-newer-files don't overwrite
existing files
that are newer than theirs
copies in the archive
--no-overwrite-dir save metadata
existing directories
--overwrite overwrite existing ones
files when extracting
--overwrite-dir overwrite existing
files when extracting (by
default)
--recursive-unlink clear the entire hierarchy before
directory extraction
--remove-files remove files after them
adding to the archive
-U, --unlink-first delete every file before
extract on top of it
-W, --verify attempt to verify the archive
after recording it

Output stream selection:

Ignore-command-error ignore codes
completion of child
processes
--no-ignore-command-error read non-zero codes
completion of child
processes as an error
-O, --to-stdout extract files to
standard output
--to-command=COMMAND
redirect
extracted files to another
program

Handling file attributes:

atime-preserve[=METHOD]
save access time
copied files by
recovery time
after reading (METHOD="replace";
used by default)
or not setting the time in
first of all
(METHOD="system")
--delay-directory-restore do not set time
changes and permissions
extracted directories up to
process termination
extraction
--group=NAME forced
set NAME to
as a group for
added files
--mode=MODE forced
install (character)
Access MODE for
added files
--mtime=DATE-OR-FILE
install for
added mtime files from
DATE-OR-FILE
-m, --touch do not extract time
file changes
--no-delay-directory-restore
undo the option
--delay-directory-restore
--no-same-owner extract files as own
own
--no-same-permissions apply the user's umask
when extracting rights
access from the archive (by
default for normal
users)
--numeric-owner use numbers instead
owner/group names
--owner=NAME forced
set NAME to
as owner for
added files
-p, --preserve-permissions, --same-permissions
extract information about
file permissions (by
default for
superuser)
--preserve equivalent to -p and -s
--same-owner try to extract files from
by the same owner
-s, --preserve-order, --same-order
sort retrieved
names in the same order as
and in the archive

Selecting and switching devices:

F, --file=ARCHIVE use file or
device ARCHIVE
--force-local archive file is
local, even if
contains a colon
-F, --info-script=NAME, --new-volume-script=NAME
run script by
end of each tape
(implied
use -M)
-L, --tape-length=N change tape after recording
NUMBER x 1024 bytes
-M, --multi-volume
create/list/retrieve
multivolume archives
--rmt-command=COMMAND
use the specified
COMMAND rmt instead of rmt
--rsh-command=COMMAND
use remote
COMMAND instead of rsh
--volno-file=FILE use/update
volume numbers in FILE

Blocking:

B, --blocking-factor=BLOCKS
number of BLOCKS x 512 bytes per
record
-B, --read-full-records reblock
when reading (for channels
4.2BSD)
-i, --ignore-zeros ignore zero blocks
in archive (i.e. EOF)
--record-size=N NUMBER of bytes per record,
multiple of 512

Archive format:

H, --format=FORMAT create an archive in the specified
format

FORMAT can be:

Gnu format GNU tar 1.13.x
oldgnu GNU format as in tar<= 1.12
pax format POSIX 1003.1-2001 (pax)
posix equivalent to pax
ustar format POSIX 1003.1-1988 (ustar)
v7 old format tar V7

Old-archive, --portability
equivalent to --format=v7

Pax-option=keyword[[:]=value][,keyword[[:]=value]]
control keywords
pax
--posix equivalent to --format=posix
-V, --label=TEXT create archive with volume name
TEXT; at
listing/retrieval
use TEXT in
as a template
substitutions

Compression options:

A, --auto-compress use archive suffix to determine
the compression program
-j, --bzip2 skip archive through bzip2
--lzma filter the archive through lzma
--use-compress-program=PROG
skip archive through
PROG (must support
-d)
-z, --gzip, --gunzip, --ungzip run archive through
gzip
-Z, --compress, --uncompress skip archive through
compress

Selecting local files:

Add-file=FILE add the specified FILE to
archive (useful if the name
starts with a dash)
--backup[=MANAGE]
make a copy before
removal, MANAGEMENT
version selection
-C, --directory=DIRECTORY change to DIRECTORY
--exclude=PATTERN to exclude files,
defined by PATTERN
--exclude-caches exclude content
directories with the CACHEDIR.TAG file
with the exception of
tagged file
--exclude-caches-all exclude directories,
containing the CACHEDIR.TAG file
--exclude-caches-under exclude all content
directories containing the file
CACHEDIR.TAG
--exclude-tag=FILE exclude directories,
containing FILE, for
except for the FILE itself
--exclude-tag-all=FILE exclude directories with
FILE
--exclude-tag-under=FILE
exclude all content
directories containing FILE
--exclude-vcs exclude CVS directories
-h, --dereference follow character
links and save files,
to which they point
--hard-dereference follow hard links; archive and
dump the files they
refer to
-K, --starting-file=MEMBER-NAME
start with member MEMBER-NAME
archived
--newer-mtime=DATE compare date and time,
only if changed
data
--no-recursion disable automatic
descent into catalogs
--no-unquote do not remove quotes from names
files read from
option -T
--null -T read lines,
ending in zero
disables the -C option
-N, --newer=DATE-OR-FILE, --after-date=DATE-OR-FILE
save only those files
which are newer
DATE-OR-FILE
--one-file-system stay local
file system at
creating an archive
-P, --absolute-names do not remove leading `/" from
file names
--recursion descend recursively
directories (default)
--suffix=STRING make a copy before
deletion, overrides
normal suffix ("~" if
only it is not overridden
environment variable
SIMPLE_BACKUP_SUFFIX)
-T, --files-from=FILE load names from FILE
to extract or
creation
--unquote remove quotes from names
files read from
-T option (default)
-X, --exclude-from=FILE exclude patterns,
listed in FILE

File name conversion:

Strip-components=N remove the specified NUMBER
initial components from
file names before
extraction
--transform=EXTENSION
use replacement
sed extensions for
file name conversions

Name wildcard options
files (affects include patterns and
exceptions):

Anchored filename start patterns
--ignore-case ignore case
--no-anchored patterns after any "/" (by
default for excluded)
--no-ignore-case case sensitive (according to
default)
--no-wildcards exact match
line
--no-wildcards-match-slash masks do not match
"/"
--wildcards use wildcards (by
default for excluded)
--wildcards-match-slash masks match "/" (by
default for excluded)

Information output:

Checkpoint[=N] display progress messages
execution every
NUMBER of entries (default
10)
--checkpoint-action=ACTION execute ACTION on each checkpoint
--index-file=FILE send verbose output
data in FILE
-l, --check-links display messages if
not all links saved
--no-quote-chars=STRING
disable quoting
characters from STRING
--quote-chars=STRING optional
quote characters from
LINES
--quoting-style=STYLE set style
quoting names. Values
for STYLE see below
-R, --block-number output block numbers
archive in each message
--show-defaults show tar values ​​by
default
--show-omitted-dirs when outputting a listing, or
checkout show all
directories, not
corresponding to the condition
search
--show-transformed-names, --show-stored-names
show file names
or archives after
transformations
--totals[=SIGNAL] output the total number of bytes
after processing the archive; from
argument - the conclusion of the general
number of bytes after delivery
this SIGNAL. Allowed
signals: SIGHUP, SIGQUIT, SIGINT, SIGUSR1
and SIGUSR2. Also allowed
use names without
SIG prefix
--utc display file modification date
UTC
-v, --verbose verbose listing
processed files
-w, --interactive, --confirmation
ask for confirmation
for every action

Compatibility options:

O at creation, equivalent
--old-archive; when extracting
equivalent to --no-same-owner

Other options:

Help output this help
--restrict disable usage
some potentially
dangerous options
--usage output short message
about using
--version display program version

Required or optional arguments
for long options are also
mandatory or optional for
corresponding short options.

The suffix for backups is `~" if it is not
set via --suffix
or SIMPLE_BACKUP_SUFFIX. Versioning can
be installed
via --backup or VERSION_CONTROL. Values ​​can
to be:

None, off do not create backups
t, numbered create numbered
backups
nil, existing numbered if exists
numbered copies otherwise plain
never, simple always create simple
backups

Valid arguments for --quoting-style options:

Literal
shell
shell-always
c
c-maybe
escape
locale
clocale

The default values ​​of *this* tar are:
--format=gnu -f- -b20 --quoting-style=escape --rmt-command=/usr/sbin/rmt
--rsh-command=/usr/bin/rsh

In this article, we will show you how to use the Tar utility to extract and create tar archives through practical examples and detailed explanations of the most common Tar options.

What is Tar?

The tar command is used to create tar archives by converting a group of files into an archive. It also has the ability to extract tar archives, display a list of files included in an archive, add additional files to an existing archive, and various other kinds of operations.

Tar supports a wide variety of compression programs such as gzip , bzip2 , lzip , lzma , lzop , xz , and compress . When creating compressed tar archives, the convention is to add the compressor suffix to the archive filename. For example, if the archive was compressed using gzip, it should be named archive.tar.gz.

Tar was originally designed to create archives by storing files on tape, hence its name " T ape AR chive".

There are two versions of tar, BSD tar and GNU tar, with some functional differences. Most Linux systems come with GNU tar pre-installed by default. If you do not have tar installed, we recommend that you first install it following our article.

Command Line Syntax

Before moving on to using the tar command, let's start by looking at the basic syntax.

Tar

  • OPERATION - Only one argument is allowed and required. Most commonly used operations:
    • --create (-c) - Create a new tar archive.
    • --extract (-x) - Extract the entire archive or one or more files from the archive.
    • --list (-t) - display a list of files included in the archive
  • OPTIONS - Most commonly used operations:
    • --verbose (-v) - Show files processed by the tar command.
    • --file=archive=name (-f archive-name) - Specifies the name of the archive file.
  • ARCHIVE_NAME - The name of the archive.
  • FILE_NAME(s) is a space-separated list of filenames to be extracted. If not provided, the entire archive will be extracted.

When executing the tar command, you can use the long or short form of tar operations and options. Long forms are more readable, while short forms are faster. Long form options are prefixed with a double dash (--). Short form options are prefixed with a single dash (-), which can be omitted.

Creating a Tar Archive

Use the -c operator to create a tar archive. For example, to create an archive file named archive.tar from files named file1 , file2 , file3 run the following command:

Tar -cf archive.tar file1 file2 file3

Here is the equivalent command using the long form options:

Tar --create --file=archive.tar file1 file2 file3

The following example will create a backup.tar archive from the /home/username directory:

Tar -cf backup.tar /home/username

You can create archives from the contents of one or more directories or files. By default, directories are archived recursively unless the --no-recursion option is specified. Use the -v option if you want to view the files that are being processed.

Creating a Tar Gz Archive

Gzip is the most popular tar file compression algorithm. When compressing tar archives with gzip, the archive name must end in either tar.gz or tgz .

To create a tar.gz archive from the given files, you can use the following command:

Tar -czf archive.tar.gz file1 file2

The -z option tells tar to compress the archive using the gzip algorithm.

Creating a Tar Bz2 archive

Another popular tar file compression algorithm is bzip2. When compressing tar archives with bzip2, the archive name must end in either tar.bz2 or tbz .

When the -j option is specified, tar will use the bzip2 archive compression algorithm.

The following command will create a tar.bz2 archive from the given files:

Tar -cjf archive.tar.bz2 file1 file2

Tar archive listing

To list the contents of a tar archive, use the --list (-t) operation.

Tar -tf archive.tar file1 file2 file3

If you specify the contents of the archive with the --verbose (-v) option, tar will print more information such as the owner, file size, timestamp, etc.:

Tar -tvf archive.tar -rw-r--r-- linuxize/users 0 2018-09-08 20:15 file1 -rw-r--r-- linuxize/users 0 2018-09-08 20:15 file2 -rw-r--r-- linuxize/users 0 2018-09-08 20:15 file3

Extracting a Tar Archive

To extract a tar archive, use the --extract (-x) operator and specify the archive filename:

Tar -xf archive.tar

Also, the -v option is usually added to print the names of the extracted files.

Tar -xvf archive.tar

By default, tar will extract the contents of the archive in the current working directory. Use --directory (-C) to extract archive files in a specific directory:

For example, to extract the contents of an archive to the /opt/files directory, you can use:

Tar -xf archive.tar -C /opt/files

Extracting Tar Gz and Tar Bz2 archives

When extracting compressed archives like tar.gz or tar.bz2 you don't need to specify the decompression option. The command is the same as when extracting a tar archive:

tar -xf archive.tar.gz tar -xf archive.tar.bz2

Extracting specific files from a tar archive

To extract specific files from a tar archive, add a space-separated list of filenames to be extracted after the archive name:

Tar -xf archive.tar file1 file2

When extracting files, you must specify your exact names, including the path, as printed by --list (-t).

Extracting one or more directories from an archive is similar to extracting files:

Tar -xf archive.tar dir1 dir2

If you try to extract a file that does not exist, you will receive an error message similar to the one below:

Tar -xf archive.tar README tar: README: Not found in archive tar: Exiting with failure status due to previous errors

Extract files from Tar archive using wildcard

To extract files from an archive based on a wildcard pattern, use the --wildcards switch and specify the pattern to prevent shell interpretation.

For example, to extract files whose names end in .js (Javascript files), you can use:

Tar -xf archive.tar --wildcards "*.js"

Adding files to an existing archive

To add files or directories to an existing tar archive, use the --append (-r) operation.

For example, to add a file named newfile to archive.tar you can use:

Tar -rvf archive.tar newfile

Removing files from a tar archive

Use the --delete operation to remove files from an archive.

For example, to remove a file named file1 from archive.tar you can use:

Tar --delete -f archive.tar file1

Output

By now you should have a good understanding of how to create and extract tar archives.

Archiver tar is the most common archiver used on Linux systems.

I decided for you (and myself as a reminder) to give in Russian the main, most common examples of creating and unpacking archives applicable in everyday life, trying to chew for simple and detailed explanations of what and how. And also tried to partially translate into Russian the use of some options. It would seem that there is nothing complicated with these archives, so what, what, but this is a trifling matter. But life tells us that no, no, but we constantly turn to manuals, look for ready-made solutions, tips on the net, and even despite all the fact that we have repeated and gone through all this many times before. But in practice, everything is simple, we have too many other concerns to keep in our heads everything that we have ever done in our lives, right? Well, why do we need all sorts of books, notes and notebooks then? That's it! :)

So. Here on the fireman's official GNU tar manual:
https://www.gnu.org/software/tar/manual/tar.txt

For every fire manual Tar for FreeBSD
freebsd.org tar manual

At the very bottom of the article is another manual, more concise, pulled from Debian 9.

Well, let's get down to the real stuff..

Used parameters (switches, options) tar

You can use any keys, both short and long, that is, from the first column or from the second. Some keys do not exist in short form, in which case only long keys should be used.

-A

catenate,
--concatenate

Attaching tar files to an archive.
-b Use 512 bytes of write in I/O blocks.
-c --create Create an archive.
-C --directory=DIR Specify the destination for extracting the contents of the specified archive. Change DIR before performing any operations. This option is order sensitive, i.e. it affects all subsequent options.
-d --diff,
--compare
The operation of comparing an archive with a given file system.
--delete Remove from archive. The arguments contain the names of the archive elements to be removed. At least one argument must be given. This option does not work with compressed archives. There is no short key equivalent.
-f --file=ARCHIVE Create a file (otherwise the output goes to the terminal). Modify ARCHIVE before doing any operations.
-g --listed-incremental=FILE Incremental archiving mode. New GNU format.
-G --incremental Incremental archiving mode. Old GNU format. When used with the "-create" option, an incremental archive is created without creating a snapshot. Thus, it is not possible to create multiple levels of incremental backups with the "--incremental" option.
--ignore-failed-read Do not quit if some files could not be read. This setting is only effective at creation time. Error warnings can be suppressed with the "--warning=failed-read" option.
-j Use bzip2 compression.
-J Use xz compression.
-k Do not overwrite existing files.
-lzma Use lzma compression.
-m --touch Do not restore modification time (only in x mode). When creating an archive, the modification time is always saved.
-O Write entries to stdout (won't rebuild disk).
-p --preserve-permissions,
--same-permissions
Repair file permissions (only in x mode). Attempt to restore
full permissions including owner, file modes, ACLs, advanced
attributes and extended file flags, if available, for each element
extracted from the archive (ignores the mask). This option causes tar to set the modes (permissions) on the extracted files exactly as written in the archive. If this option is not used, the current "umask" setting limits the permissions on the extracted files. This setting is enabled by default when "tar" is run as root.
This option has no meaning with "-list" ("-t").
-P --absolute-names Preserve pathnames. When creating archives, leading slashes are not removed from filenames. By default, absolute pathnames (names that begin with /) strip the leading slash both when creating archives and when extracting from them. In addition, Tar will refuse to unpack archive files whose names contain ".." or whose target directory is changed with a symbolic link. This setting disables this behavior. Typically, when creating an archive, "tar" removes the leading "/" character from member names, and when extracting from a "tar" archive, names if they have a leading "/" character or an internal "..". This option disables this behavior.
-r --append Adding a file to an archive.
tar -rf archive.tar add.txt
--strip-components=NUMBER Removes N leading components from filenames on extraction.
-S --sparse If the file turns out to be sparse, it will be specially processed, which will reduce the size of the future archive. This option is only meaningful when creating or updating archives. This does not affect extraction. However, be aware that the "-sparse" option can present a serious disadvantage. You may have to read the file before attempting to archive it to determine the contents of the file, so the file may be read twice in total. This behavior depends on your OS or file system, which does not support the "SEEK_HOLE/SEEK_DATA" function. However, it is recommended to use "--sparse" when performing a file system backup to avoid archiving the expanded forms of files stored on the system. You can be sure that the archive will never take up more space on the media than the files on the disk.
-t Get the table of contents (content) from the archive (list files).
-u --update Add files to the archive that are newer than the corresponding copy in the archive. The arguments have the same meaning as with the -c and -r options.
-v --verbose Displaying a list of packed files while working.
-w interactive mode.
-W This option is used to check the archive.
-x --extract,
--get
File extraction.
-z --gzip,
--gunzip,
--ungzip
Use gzip compression.

Create a tar.gz archive

# Task: Create a tar.gz archive with gzip compression. # # You don't have to go to the right directory, you can run the command from anywhere. # # 1. Specify the -czf switches. # 2. Specify the full path and name of the new archive. # 3. Specify the full path to the source directory. # # This will create a new.tar.gz archive in the /archives directory with the contents # of the /home/documents directory. tar -czf /archives/new.tar.gz /home/documents

Create tar.gz backup with paths and permissions preserved

# Task: Create a tar.gz backup with gzip compression. # # You don't have to go to the right directory, you can run the command from anywhere. # # 1. Specify the -cPzf switches. # 2. Specify the full path and name of the new archive. # 3. Specify the full path to the source directory. # # This will create a new.tar.gz archive in the /archives directory with the contents # of the /home/user/site directory. tar -cPzf /backups/new.tar.gz /home/user/site

Unpack the tar.gz archive into the current directory

# Task: Unpack the tar.gz archive into the current directory. # # 1. Go to the desired directory. # 2. Specify the -xzf switches. # 3. Specify the full path to the source archive. # # As a result of execution, the contents of the archive.tar.gz archive will be unpacked in the directory we are currently in, # in this case it will be in /home/here. # Go to the desired directory cd /home/here # Unpack the contents into the current directory, specifying the full path to the source archive. tar -xzf /pub/downloads/archive.tar.gz


Unpack the tar.gz archive to the specified directory

# Task: Unpack the tar.gz archive into the specified directory. # # You don't have to go to the right directory, you can run the command from anywhere. # # 1. Specify switches -xzf. # 2. Specify the full path to the source archive. # 3. Specify the full path of the destination using the -C switch. # # As a result of execution, the contents of the archive.tar.gz archive will be unpacked to the # specified directory, in this case the /home/here directory. tar -xzf /pub/downloads/archive.tar.gz -C /home/here


Unpack the contents of the tar.gz archive into the current directory, preserving permissions

# Task: Restore the contents of the archive while maintaining/restoring access rights. # # To unpack the contents of the archive in this mode, add the -p switch. # # 1. Go to the desired directory. # 2. Specify switches -xzpf. # 3. Specify the full path to the source archive. # # As a result of executing the command, the contents of the backup.tar.gz archive will be unpacked with # restored access rights that were previously at the time of archiving the files. # The contents of the archive.tar.gz archive will be unpacked in the directory we are currently # in, in this case it will be /home/here. # Go to the desired directory cd /home/here # Unpack the contents into the current directory, specifying the full path to the source archive. tar -xzpf /pub/downloads/backup.tar.gz


Unpack the contents of the tar.gz archive into the specified directory while maintaining access rights

# Task: Restore the contents of the archive while maintaining/restoring access rights. # # To unpack the contents of the archive in this mode, add the -p switch. # # 1. Specify switches -xzpf. # 2. Specify the full path to the source archive. # 3. Specify the full path of the destination using the -C switch. # # As a result of executing the command, the contents of the backup.tar.gz archive will be unpacked with # restored access rights that were previously at the time of archiving the files. # The contents of the archive.tar.gz archive will be unpacked to the specified directory, in this case # the /home/here directory. tar -xzpf /pub/downloads/backup.tar.gz -C /home/here


Restore the contents of a tar.gz archive, preserving paths and permissions

# Task: Restore the contents of the archive with the preservation of paths and access rights. # This method is ideal for backup and restore files. # This mode is not incremental, but is also supported not only by Linux, but # by FreeBSD as well. Note: FreeBSD does not support incremental mode. # # To unpack the contents of the archive while preserving paths and permissions, add # the -p switch to restore permissions, and the -P switch to restore the directory hierarchy # from the root. This option does not remove leading slashes from element names. # # 1. Specify switches -xPzpf. # 2. Specify the full path to the source archive. # # As a result of executing the command, the contents of the backup.tar.gz archive will be unpacked in the same form and # structure with restored access rights that were previously at the moment # of archiving. As the files are restored, the directory hierarchy (if it doesn't exist) will # be recreated from scratch from the root directory itself. Files that match on the path will # be replaced/restored, existing other files will not be affected. # # Note: in this mode, the -P switch cannot be used simultaneously with the -C switch, i.e. # the destination directory cannot be specified. It just won't work, it will still restore # the original directory and file structure. If you want to specify your restore directory, # just remove the -P option from the prompt. tar -xPzpf /pub/downloads/backup.tar.gz


Unpack the archive into the specified directory with access rights preserved, but discarding, for example, three initial directories (Extract a separate directory branch)

# Task: Check out a separate directory branch. # # To unpack part of the archive hierarchy (with permissions preserved, the -p option is also added), # we will use the new additional option "--strip-components=NUMBER", where # NUMBER is the number of stripped (left) leading elements. # # In the archive /archives/sitebk.2017.09.07.tar.gz: # /usr/home/user/virtual/site # Will be extracted from the archive to the directory /home/here: # virtual/site # tar -xzpf /usr /sitebk.2017.09.07.tar.gz --strip-components=3 -C /home/here

Add file to tar archive

# Add the add.txt file to the archive.tar archive. # Don't forget the -P switch if needed. tar -rf archive.tar add.txt

Original MAN GNU tar Debian

TAR(1) GNU TAR Manual TAR(1) NAME tar - an archiving utility SYNOPSIS Traditional usage tar (A|c|d|r|t|u|x) UNIX-style usage tar -A ARCHIVE ARCHIVE tar -c [- f ARCHIVE] tar -d [-f ARCHIVE] tar -t [-f ARCHIVE] tar -r [-f ARCHIVE] tar -u [-f ARCHIVE] tar -x [-f ARCHIVE] GNU-style usage tar (- -catenate|--concatenate) ARCHIVE ARCHIVE tar --create [--file ARCHIVE] tar (--diff|--compare) [--file ARCHIVE] tar --delete [--file ARCHIVE] tar --append [ -f ARCHIVE] tar --list [-f ARCHIVE] tar --test-label [--file ARCHIVE] tar --update [--file ARCHIVE] tar --update [-f ARCHIVE] tar (--extract| --get) [-f ARCHIVE] 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 http://www.gnu.org/software/tar/manual 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 has been processed are treated as non-optional 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 a.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 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. Options that take arguments (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 a.tar /etc or tar -c -v -f a.tar /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. Meaning of non-optional arguments depends on the operation mode requested. -A, --catenate, --concatenate Append archive 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 if 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 to this option. -u, --update Append files which are newer than the corresponding copy in the archive. Arguments have the same meaning as with -c and -r options. -x, --extract, --get Extract files from an archive. Arguments are optional. When given, they specify the names of the archive members to be extracted. --show-defaults Show built-in defaults for various tar options and exit. No arguments are allowed. -?, --help Display a short option summary and exit. No allowed arguments. --usage Display a list of available options and exit. No allowed arguments. --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, create a copy of the snapshot file created during the level N-1, and use it as FILE. When listing or extracting, the actual contents 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 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 sought 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 version of the sparse format to use (implies --sparse). 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 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. --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 output. 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 +. NEWGRP and NEWGID need not be listed in the system group database.--mode=CHANGES Force symbolic mode CHANGES for added files. --mtime=DATE-OR-FILE Set mtime for added files. er 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 +. and NEWUID need not be listed in the system user database. -p, --preserve-permissions, --same-permissions extract information about file permissions (default for superuser) --preserve Same as both -p and -s. --same-owner Try extracting files with the same ownership as exists in the archive (default for superuser). -s, --preserve-order, --same-order Sort names to extract to match 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 con‐ siderably speed up archiving. 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 POSIX regular expression, e.g. --xat-trs-exclude="^user.", to exclude attributes from the user namespace. --xattrs-include=PATTERN Specify the include pattern for xattr keys. PATTERN is a POSIX regular expression. 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. as the machine name or IP address, and the part after it as the file or device pathname, eg: --file=remotehost:/dev/sr0 An optional username can be prefixed to the hostname, placing a @ sign between them. 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 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 con‐ tain 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). 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 val‐ ues 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 subdi‐ rectories. --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: .cvsig‐ nore, .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 --verba‐ tim-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 ctime 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 sig‐ nal 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. --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 messages 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: file is the archive; not dumped" file-removed "%s: File removed before we read it" file-changed "%s: file changed as we read it" 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 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 compres‐ sor 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), tar(5), xz(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: http://www.gnu.org/software/tar/manual BUG REPORTS Report bugs to . COPYRIGHT Copyright © 2013 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. March 23, 2016