TAR(1)

๐Ÿ“ฆ
version 1.35 ยท 2 versions
, in centos-stream 10, fedora 43, fedora 44

๐ŸŽ€ NAME ๐ŸŽ€

okay bestie, this is the TAR(1) page from the GNU TAR Manual ๐Ÿ’– and tar is literally just "an archiving utility" ๐Ÿ“ฆโœจ

๐Ÿ’… 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 ๐Ÿ“

ngl this part is so important ๐Ÿ™ˆ This manpage is just a short description of GNU tar. If you want the full deep dive, with examples and usage recommendations, go read the GNU Tar Manual, which comes in texinfo format. If the info reader and the tar docs are properly installed on your system, this command

info tar

should pull up the complete manual for you ๐Ÿ“–

You can also read the manual through the info mode in emacs(1), or find it in a bunch of formats online at

https://www.gnu.org/software/tar/manual
โš ๏ธ bestie, if this page and the GNU Tar Manual ever disagree, the GNU Tar Manual wins. It's the authoritative source, no debate ๐Ÿ’…

๐ŸŒˆ DESCRIPTION ๐ŸŒˆ

okay so GNU tar is an archiving program that lets you stash multiple files into a single file (an archive) and then mess around with those archives ๐Ÿ“ฆ๐Ÿ’– The archive can be a regular file or a device, like a tape drive (which is literally where the name comes from, it stands for tape archiver ๐Ÿ“ผ). It can live on your local machine or on a remote one, which is giving flexibility ๐Ÿฆ‹

๐ŸŽ€ Option styles

okay this part is the vibe check for how you actually type options โœจ GNU tar lets you write options in three different styles, and honestly they're all valid, you just need to know which one you're looking at ๐Ÿ‘€

In the traditional style, the first argument is a cluster of option letters, and every argument after that supplies the arguments for whichever options need them. The arguments get read in the same order as the option letters. Any command line words left over after all the options are processed are treated as non-option arguments, which means file or archive member names ๐Ÿ“‚

For example, the c option means create the archive, the v option asks for verbose output, and the f option takes an argument that names the archive you're working on. So this command, written in the traditional style, tells tar to store everything from the directory /etc into the archive file etc.tar, and it'll verbosely list each file as it goes ๐ŸŒธ

tar cfv etc.tar /etc

In UNIX or short-option style, every option letter gets a single dash in front, like other command line tools ๐Ÿงš If an option takes an argument, that argument follows it, either as its own separate command line word or stuck right after the option. BUT if the option takes an optional argument, the argument has to come right after the option letter with zero whitespace in between, like -g/tmp/snar.db ๐Ÿ™ˆ

You can clump any number of options that don't take arguments together after one dash, like -vkp. An option that does take an argument (mandatory or optional) can sit at the end of that cluster, like -vkpf a.tar ๐Ÿ’…

Here's the example command from up top, written in short-option style:

tar -cvf etc.tar /etc

or

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

Then there's the GNU or long-option style, where each option starts with two dashes and has a meaningful name made of lower-case letters and dashes โœจ You can shorten a long option down to its initial letters, as long as that doesn't make it ambiguous. Arguments to long options can be a separate command line word, right after the option, or joined to the option with an equals sign and no whitespace. Optional arguments always have to use the equals-sign method, no exceptions ๐Ÿซถ

Here are a few ways to write the example command in this style:

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

or, abbreviating some options:

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

Just a heads up: the options in all three styles can be mixed together in one command. That said, mixing them with the old options isn't encouraged ๐Ÿ™ˆ

๐Ÿ“ Operation mode

The options listed in the table below tell GNU tar what operation it's supposed to perform ๐Ÿ’œ You have to give exactly one of them. What the non-option arguments mean depends on which operation mode you picked ๐Ÿ‘‘

  • -A, --catenate, --concatenate โ€” okay so this one appends archives to the end of another archive ๐Ÿ“ฆ The arguments are the names of the archives you want to tack on. All of them have to be the same format as the archive they're getting appended to, otherwise the result might be unusable with non-GNU versions of tar ๐Ÿ’€ Also, when you give more than one archive, the members from every archive except the first one will only be accessible in the resulting archive if you use the -i (--ignore-zeros) option.

Compressed archives cannot be concatenated. ๐Ÿšซ

  • -c, --create โ€” make a brand new archive โœจ The arguments are the names of the files you want archived. Directories get archived recursively, unless you pass the --no-recursion option ๐ŸŒณ
  • -d, --diff, --compare โ€” find the differences between the archive and the file system ๐Ÿ” The arguments are optional and name the archive members you want compared. If you don't give any, the current working directory is assumed ๐Ÿ“
  • --delete โ€” delete stuff from the archive ๐Ÿ—‘๏ธ The arguments are the names of the archive members to remove. You need to give at least one argument, no freebies here.

This option does not work on compressed archives. There's also no short option for it. ๐Ÿ™…โ€โ™€๏ธ

  • -r, --append โ€” append files to the end of an archive ๐Ÿ’– The arguments mean the same thing they do for -c (--create).
  • -t, --list โ€” list the contents of an archive ๐Ÿ“œ The arguments are optional. If you give some, they name the members you want listed.
  • --test-label โ€” test the archive volume label and then exit ๐Ÿท๏ธ Used without arguments, it prints the volume label (if there is one) and exits with status 0. When you give one or more command line arguments, tar compares the volume label against each argument. It exits with code 0 if it finds a match, and with code 1 otherwise. No output is displayed unless you combine it with the -v (--verbose) option.

There's no short option equivalent for this one ๐Ÿ™ˆ

  • -u, --update โ€” append files that are newer than their matching copy in the archive โฐ The arguments mean the same thing they do for -c and -r. Here's the tea though: newer files don't replace their old copies in the archive. They get appended to the end instead, so the resulting archive can have several members with the same name, one for each version of the file ๐Ÿฆ‹
  • -x, --extract, --get โ€” extract files from an archive ๐ŸŽ The arguments are optional. If you give some, they name the archive members you want extracted.
  • --show-defaults โ€” show the built-in defaults for various tar options and then exit ๐Ÿง
  • -?, --help โ€” display a short option summary and exit ๐Ÿ’โ€โ™€๏ธ
  • --usage โ€” display a list of the available options and exit ๐Ÿ“‹
  • --version โ€” print the program version and copyright information, then exit ๐ŸŒˆ

๐Ÿ‘‘ OPTIONS ๐Ÿ‘‘

๐Ÿง Operation modifiers

  • --check-device โ€” check device numbers when creating incremental archives. This is the default ๐Ÿ”ง
  • -g, --listed-incremental=FILE โ€” handle new GNU-format incremental backups ๐Ÿ“ธ FILE is the name of a snapshot file, where tar stores extra info it uses to figure out which files changed since the previous incremental dump, and which therefore need to be dumped again. If FILE doesn't exist when you're creating an archive, tar creates it and adds all files to the resulting archive (this is the level 0 dump). To make incremental archives of a non-zero level N, you need a copy of the snapshot file made for level N-1, and you use that copy as FILE ๐Ÿง 

When you're listing or extracting, the actual content of FILE doesn't get inspected. It's only needed because of syntax requirements, so it's super common to use /dev/null in its place ๐Ÿ•ณ๏ธ

  • --hole-detection=METHOD โ€” use METHOD to detect holes in sparse files ๐Ÿ•ณ๏ธ This option implies --sparse. The valid values for METHOD are seek and raw. The default is seek, with a fallback to raw when seek isn't applicable.
  • -G, --incremental โ€” handle old GNU-format incremental backups ๐Ÿ—‚๏ธ
  • --ignore-failed-read โ€” don't exit with a nonzero status just because some files couldn't be read ๐Ÿ™ƒ
  • --level=NUMBER โ€” set the dump level for a created listed-incremental archive ๐ŸŽš๏ธ Right now, only --level=0 actually means anything. It tells tar to truncate the snapshot file before dumping, which forces a level 0 dump.
  • -n, --seek โ€” assume the archive is seekable ๐Ÿ”Ž Normally tar figures out on its own whether the archive can be seeked, but this option is for when that detection goes wrong. It only takes effect if the archive is open for reading (for example, with --list or --extract).
  • --no-check-device โ€” don't 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 only valid with one of these subcommands: --delete, --diff, --extract or --list, and only when a list of files is given either on the command line or via the -T option. The default N is 1.
  • --restrict โ€” disable some potentially harmful options ๐Ÿ›ก๏ธ
  • --sparse-version=MAJOR[.MINOR] โ€” set which version of the sparse format to use ๐Ÿงฉ This option implies --sparse. The valid argument values are 0.0, 0.1 and 1.0. For a detailed discussion of sparse formats, check out the GNU Tar Manual, appendix D, "Sparse Formats". You can read it with the info reader by running this command: info tar 'Sparse Formats' ๐Ÿ“–๐Ÿ’œ

-S, --sparse

Okay so this one is for the files with secret empty holes in them ๐Ÿ•ณ๏ธโœจ Some files in your file system have segments that were never actually written (usually database files made by stuff like DBM ๐Ÿ’€). With this option, tar tries to figure out whether the file is sparse before archiving it, and if it is, it skips dumping those empty parts so the archive comes out smaller. Efficiency is giving ๐Ÿ’…

โœจ Overwrite control โœจ

These options decide what tar does when you're extracting a file and there's already a copy of it sitting on disk. Major decision-making energy ๐Ÿ‘‘

  • -k, --keep-old-files โ€” Don't replace existing files when extracting. Your old stuff stays put ๐Ÿงธ
  • --keep-newer-files โ€” Don't replace existing files that are newer than their archive copies. If your version is fresher, tar leaves it alone ๐Ÿซถ
  • --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 everything into DIR. If you use it with no argument, tar makes a subdirectory named after the archive's base name, with the standard compression suffixes that --auto-compress recognizes chopped off ๐ŸŒธ
  • --overwrite โ€” Overwrite existing files when extracting ๐Ÿ”ฅ
  • --overwrite-dir โ€” Overwrite metadata of existing directories when extracting (this is the default) ๐Ÿ’–
  • --recursive-unlink โ€” Recursively remove all files in the directory before extracting it. Full clean sweep ๐Ÿงน
  • --remove-files โ€” Remove files from disk after adding them to the archive. Gone after archiving, no cap ๐Ÿ’€
  • --skip-old-files โ€” Don't replace existing files when extracting, and silently skip over them. No drama, no notification ๐Ÿ™ˆ
  • -U, --unlink-first โ€” Remove each file before extracting over it ๐Ÿฆ‹
  • -W, --verify โ€” Verify the archive after writing it. Double-checking is a whole vibe โœจ

โœจ Output stream selection โœจ

Where do the files end up? Let's talk destinations ๐ŸŽ€

  • --ignore-command-error โ€” Ignore subprocess exit codes ๐Ÿ™ƒ
  • --no-ignore-command-error โ€” Treat non-zero exit codes of children as errors (this is the default) ๐Ÿšจ
  • -O, --to-stdout โ€” Extract files to standard output ๐Ÿ“ค
  • --to-command=COMMAND โ€” Pipe extracted files into COMMAND. The argument is the pathname of an external program, and you can add command line arguments too. That program gets invoked, and the contents of the file being extracted get fed to it on its standard input. Extra info comes through these environment variables ๐Ÿงš
    • TAR_FILETYPE โ€” The type of the file, given as a single letter with this 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 โ€” The file mode, as an octal number ๐Ÿ”ข
  • TAR_FILENAME โ€” The name of the file ๐Ÿ“
  • TAR_REALNAME โ€” The name of the file as stored in the archive ๐Ÿ—‚๏ธ
  • TAR_UNAME โ€” The name of the file owner ๐Ÿ‘ค
  • TAR_GNAME โ€” The name of the file owner's group ๐Ÿ‘ฅ
  • TAR_ATIME โ€” The time of last access. It's a decimal number of seconds since the Epoch. If the archive stores times with nanosecond precision, the nanoseconds get tacked on after a decimal point โฐ
  • TAR_MTIME โ€” The time of last modification ๐Ÿ•ฐ๏ธ
  • TAR_CTIME โ€” The time of last status change ๐Ÿ•’
  • TAR_SIZE โ€” The size of the file ๐Ÿ“
  • TAR_UID โ€” The UID of the file owner ๐Ÿ†”
  • TAR_GID โ€” The GID of the file owner ๐Ÿ†”

Plus, these variables tell you about the tar operation mode and the archive being processed. Extra context, extra iconic ๐ŸŒˆ

  • TAR_VERSION โ€” The GNU tar version number ๐Ÿท๏ธ
  • TAR_ARCHIVE โ€” The name of the archive tar is processing ๐Ÿ“ฆ
  • TAR_BLOCKING_FACTOR โ€” The current blocking factor, meaning the number of 512-byte blocks in a record ๐Ÿงฑ
  • TAR_VOLUME โ€” The ordinal number of the volume tar is processing (only set when reading a multi-volume archive) ๐Ÿ“š
  • TAR_FORMAT โ€” The 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 currently running ๐Ÿƒโ€โ™€๏ธ

โœจ Handling of file attributes โœจ

This is the glow-up section, where we get into how files look and who they belong to ๐Ÿชž๐Ÿ’…

  • --atime-preserve[=METHOD] โ€” Preserve access times on dumped files. You can do this either by restoring the times after reading (METHOD=replace, which 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 one when you're extracting from an archive with unusual member ordering ๐Ÿงฉ
  • --group=NAME[:GID] โ€” Force NAME as the group for added files. If GID isn't supplied, NAME can be either a user name or a numeric GID. In that case, the missing part (the GID or the name) gets inferred from the current host's group database ๐Ÿ‘ฏ

When used with --group-map=FILE, this only affects files whose owner group isn't listed in FILE ๐ŸŽฏ

  • --group-map=FILE โ€” Read the group translation map from FILE. Empty lines get ignored. Comments start with a # sign and run to the end of the line. Each non-empty line in FILE defines a translation for a single group. Each line has to contain two fields, separated 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 also has to be either a valid group name or a +GID. Otherwise, neither NEWGRP nor NEWGID needs to be in the system group database. ๐Ÿ—บ๏ธ

The result: every input file with owner group OLDGRP gets stored in the archive with owner group NEWGRP and GID NEWGID ๐Ÿ”

  • --mode=CHANGES โ€” Force the symbolic mode CHANGES onto added files ๐ŸŽจ
  • --mtime=DATE-OR-FILE โ€” Set the mtime for added files. DATE-OR-FILE is either a date/time in almost any format you can think of, or the name of an existing file. If it's a file, that file's mtime gets used ๐Ÿ“…
  • -m, --touch โ€” Don't extract file modified time ๐Ÿซฅ
  • --no-delay-directory-restore โ€” Cancel the effect of the earlier --delay-directory-restore option ๐Ÿ™…โ€โ™€๏ธ
  • --no-same-owner โ€” Extract files as yourself (this is the default for ordinary users) ๐Ÿ™‹โ€โ™€๏ธ
  • --no-same-permissions โ€” Apply the user's umask when extracting permissions from the archive (this is the default for ordinary users) ๐Ÿ›ก๏ธ
  • --numeric-owner โ€” Always use numbers for user/group names ๐Ÿ”ข
  • --owner=NAME[:UID] โ€” Force NAME as the owner for added files. If UID isn't supplied, NAME can be either a user name or a numeric UID. In that case, the missing part (the UID or the name) gets inferred from the current host's user database ๐Ÿชช

When used with --owner-map=FILE, this only affects files whose owner isn't listed in FILE ๐ŸŽฏ

  • --owner-map=FILE โ€” Read the owner translation map from FILE. Empty lines get ignored. Comments start with a # sign and run to the end of the line. Each non-empty line in FILE defines a translation for a single UID. Each line has to contain two fields, separated 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 also has to be either a valid user name or a +UID. Otherwise, neither NEWUSR nor NEWUID needs to be in the system user database. ๐Ÿ—บ๏ธ

The result: every input file owned by OLDUSR gets stored in the archive with owner name NEWUSR and UID NEWUID ๐Ÿ”

  • -p, --preserve-permissions, --same-permissions โ€” Set the permissions of extracted files to whatever is recorded in the archive (this is the default for the superuser) ๐Ÿ”
  • --same-owner โ€” Try extracting files with the same ownership they have in the archive (this is the default for the 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 whatever order the operating system returns them ๐Ÿคทโ€โ™€๏ธ

--sort=name makes the member ordering in the created archive uniform and reproducible ๐Ÿ”

--sort=inode cuts down on the number of disk seeks made while creating the archive, so it can seriously speed things up ๐ŸŽ๏ธ This sorting order only works if the underlying system provides the information it needs โš ๏ธ

โœจ Extended file attributes โœจ

The extra stuff that rides along with your files ๐Ÿ’œ

  • --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, for example --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 โœจ

Picking where your archive lives, and letting it travel ๐Ÿงšโœจ

  • -f, --file=ARCHIVE โ€” Use the archive file or device ARCHIVE. If you don't give this option, tar first checks the environment variable TAPE. If that's set, its value becomes the archive name. Otherwise, tar falls back on the compiled-in default. You can check that default with the --show-defaults option, or at the end of the tar --help output ๐ŸŽ€

An archive name with a colon in it points to a file or device on a remote machine. The part before the colon is the machine name or IP address, and the part after it is the file or device pathname, like this:

--file=remotehost:/dev/sr0

You can also put a username in front of the hostname, with an @ sign between them ๐Ÿ’Œ

By default, the remote host gets accessed through the rsh(1) command ๐Ÿ”Œ but nowadays ssh(1) is the go-to, so you can switch with this line:

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

The remote machine should have the rmt(8) command installed ๐Ÿ–ฅ๏ธ If its pathname doesn't match tar's default, just tell tar the right one with the --rmt-command option. Easy peasy ๐Ÿ’…

  • --force-local โ€” treats the archive file as local, even if its name has a colon in it ๐Ÿซถ
  • -F, --info-script=COMMAND, --new-volume-script=COMMAND โ€” runs COMMAND at the end of each tape (this one implies -M) โœจ The command can take arguments too. When it kicks off, it inherits tar's environment plus these bestie variables:
    • TAR_VERSION โ€” the GNU tar version number ๐Ÿ”ข
    • TAR_ARCHIVE โ€” the name of the archive tar is processing ๐Ÿ“ฆ
    • TAR_BLOCKING_FACTOR โ€” the current blocking factor, aka how many 512-byte blocks fit in a record ๐Ÿงฑ
    • TAR_VOLUME โ€” the ordinal number of the volume tar is processing (only set when reading a multi-volume archive) ๐Ÿ“š
    • TAR_FORMAT โ€” the format of the archive being processed. One of: gnu, oldgnu, posix, ustar, v7 ๐ŸŽ€
    • TAR_SUBCOMMAND โ€” a short option (with a leading dash) describing what tar is doing right now ๐Ÿƒโ€โ™€๏ธ
    • TAR_FD โ€” a file descriptor you can use to tell tar the new volume name ๐Ÿฆ‹
If the info script fails, tar exits. Otherwise, it moves on and starts writing the next volume. ๐Ÿ˜ญ
  • -L, --tape-length=N โ€” changes tape after writing Nx1024 bytes ๐Ÿ“ผ If N has a size suffix (see the subsection Size suffixes below), that suffix sets the multiplicative factor instead of 1024.

This option implies -M.

  • -M, --multi-volume โ€” create, list, or extract a multi-volume archive ๐Ÿ—‚๏ธ
  • --rmt-command=COMMAND โ€” uses COMMAND instead of rmt when accessing remote archives ๐Ÿ›ฐ๏ธ See the description of the -f option, above.
  • --rsh-command=COMMAND โ€” uses COMMAND instead of rsh when accessing remote archives ๐Ÿ” See the description of the -f option, above.
  • --volno-file=FILE โ€” when used together with --multi-volume, tar keeps track of which volume of a multi-volume archive it's on, storing that in FILE ๐Ÿงพ

โœจ Device blocking โœจ

  • -b, --blocking-factor=BLOCKS โ€” sets the record size to BLOCKSx512 bytes ๐Ÿงฉ
  • -B, --read-full-records โ€” when listing or extracting, accepts incomplete input records after the end-of-file marker ๐Ÿ™ˆ
  • -i, --ignore-zeros โ€” ignores zeroed blocks in the archive ๐ŸงŠ Normally, two consecutive 512-blocks filled with zeroes mean EOF, and tar stops reading once it hits them. This option tells it to keep reading, which is handy when reading archives made with the -A option.
  • --record-size=NUMBER โ€” sets the record size ๐Ÿ“ NUMBER is the number of bytes per record, and it must be a multiple of 512. You can add a size suffix, like --record-size=10K for 10 Kilobytes. Check the subsection Size suffixes for the list of valid suffixes ๐Ÿ’ซ

๐Ÿฆ‹ Archive format selection ๐Ÿฆ‹

  • -H, --format=FORMAT โ€” creates an archive in 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]]... โ€” controls pax keywords when creating PAX archives (-H pax) ๐ŸŒธ This is equivalent to the -o option of the pax(1) utility.
  • --posix โ€” same as --format=posix ๐Ÿ“ฎ
  • -V, --label=TEXT โ€” creates an archive with the volume name TEXT ๐Ÿท๏ธ When listing or extracting, TEXT is used as a globbing pattern for the volume name ๐Ÿ”

๐Ÿ—œ๏ธ Compression options ๐Ÿ—œ๏ธ

  • -a, --auto-compress โ€” uses the archive suffix to figure out which compression program to use ๐Ÿช„
  • -I, --use-compress-program=COMMAND โ€” filters data through COMMAND ๐Ÿงƒ It must accept the -d option (for decompression), and the argument can include command line options.
  • -j, --bzip2 โ€” filters the archive through bzip2(1) ๐Ÿ“
  • -J, --xz โ€” filters the archive through xz(1) ๐Ÿ’œ
  • --lzip โ€” filters the archive through lzip(1) ๐ŸŒŠ
  • --lzma โ€” filters the archive through lzma(1) ๐ŸŒ™
  • --lzop โ€” filters the archive through lzop(1) ๐Ÿซง
  • --no-auto-compress โ€” don't use the archive suffix to pick the compression program ๐Ÿ™…โ€โ™€๏ธ
  • -z, --gzip, --gunzip, --ungzip โ€” filters the archive through gzip(1) ๐Ÿญ
  • -Z, --compress, --uncompress โ€” filters the archive through compress(1) ๐Ÿซ 
  • --zstd โ€” filters the archive through zstd(1) โšก

๐ŸŒˆ Local file selection ๐ŸŒˆ

  • --add-file=FILE โ€” adds FILE to the archive. Super useful if its name starts with a dash ๐Ÿชฝ
  • --backup[=CONTROL] โ€” makes a backup before removal ๐Ÿ›Ÿ The CONTROL argument, if you give it, sets 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 already exist, simple backups otherwise ๐Ÿค”
    • never, simple โ€” always make simple backups ๐Ÿซถ

If CONTROL isn't given, the value comes from the VERSION_CONTROL environment variable. If that isn't set either, existing is assumed.

  • -C, --directory=DIR โ€” changes to DIR before doing anything else ๐Ÿ“‚ This option is order-sensitive, meaning it affects all the options that come after it.
  • --exclude=PATTERN โ€” excludes files matching PATTERN, a glob(3)-style wildcard pattern ๐Ÿšท
  • --exclude-backups โ€” excludes backup and lock files ๐Ÿ”’
  • --exclude-caches โ€” excludes the contents of directories containing the file CACHEDIR.TAG, except for the tag file itself ๐Ÿ—‘๏ธ
  • --exclude-caches-all โ€” excludes directories containing the file CACHEDIR.TAG, along with the file itself ๐Ÿ’€
  • --exclude-caches-under โ€” excludes everything under directories containing CACHEDIR.TAG ๐Ÿ™ƒ
  • --exclude-ignore=FILE โ€” before dumping a directory, checks whether it contains FILE. If it does, exclusion patterns get read from that file. The patterns only affect the directory itself ๐Ÿชž
  • --exclude-ignore-recursive=FILE โ€” same as --exclude-ignore, except the patterns from FILE affect both the directory and all of its subdirectories ๐ŸŒณ
  • --exclude-tag=FILE โ€” excludes the contents of directories containing FILE, except for FILE itself ๐Ÿท๏ธ
  • --exclude-tag-all=FILE โ€” excludes directories containing FILE ๐Ÿšช
  • --exclude-tag-under=FILE โ€” excludes everything under directories containing FILE ๐Ÿงน
  • --exclude-vcs โ€” excludes version control system directories ๐Ÿ™…โ€โ™€๏ธ
  • --exclude-vcs-ignores โ€” excludes files matching patterns read from VCS-specific ignore files. The supported files are: .cvsignore, .gitignore, .bzrignore, and .hgignore ๐Ÿซง
  • -h, --dereference โ€” follows symlinks, archiving and dumping the files they point to ๐Ÿ”—
  • --hard-dereference โ€” follows hard links, archiving and dumping the files they refer to ๐Ÿชข
  • -K, --starting-file=MEMBER โ€” begins at the given member in the archive ๐Ÿ
  • --newer-mtime=DATE โ€” works on files whose data changed after DATE ๐Ÿ•‘ If DATE starts with / or ., it's taken to be a file name, and that file's mtime is used as the date.
  • --no-null โ€” disables the effect of the previous --null option ๐Ÿ™…โ€โ™€๏ธ
  • --no-recursion โ€” stops tar from automatically descending into directories ๐Ÿ›‘
  • --no-unquote โ€” doesn't unquote input file or member names ๐Ÿซฅ
  • --no-verbatim-files-from โ€” treats each line read from a file list as if it were typed on the command line ๐Ÿ“ That means leading and trailing whitespace gets removed, and if the resulting string starts with a dash, it's treated as a tar command line option.

This is the default behavior. The --no-verbatim-files-from option exists so you can restore it after using --verbatim-files-from ๐Ÿ”

This option is positional: it affects all --files-from options that come after it, until a --verbatim-files-from option or the end of the line, whichever shows up first ๐Ÿ“

It's implied by the --no-null option.

  • --null โ€” tells subsequent -T options to read null-terminated names verbatim, which disables the special handling of names that start with a dash ๐Ÿซง

See also --verbatim-files-from.

  • -N, --newer=DATE, --after-date=DATE โ€” only stores files newer than DATE ๐Ÿ—“๏ธ If DATE starts with / or ., it's taken to be a file name, and that file's mtime is used as the date.
  • --one-file-system โ€” stays in the local file system when creating an archive ๐Ÿ 
  • -P, --absolute-names โ€” doesn't strip leading slashes from file names when creating archives โš ๏ธ
  • --recursion โ€” recurses into directories (this is the default) ๐ŸŒ€
  • --suffix=STRING โ€” makes a backup before removal, overriding the usual suffix ๐Ÿฉน The default suffix is ~, unless you override it with the SIMPLE_BACKUP_SUFFIX environment variable.
  • -T, --files-from=FILE โ€” gets the names to extract or create from FILE ๐Ÿ“œ

Unless specified otherwise, FILE must contain a list of names separated by ASCII LF (so 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 a tar command line option.

If that behavior is undesirable, you can turn it off with the --verbatim-files-from option ๐Ÿ™…โ€โ™€๏ธ

The --null option tells tar that the names in FILE are separated by the ASCII NUL character instead of LF. It's useful if the list is generated by the find(1) -print0 predicate ๐Ÿงš

  • --unquote โ€” unquotes file or member names (this is the default) ๐ŸŽ€
  • --verbatim-files-from โ€” treats each line 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. By default, names in file lists are handled as if they were typed on the command line, so any name starting with a dash is treated as a tar option. The --verbatim-files-from option turns that behavior off โœจ

This bit of OPTIONS was already covered, so I'll pick up right where the verbatim files stuff leaves off ๐ŸŽ€

Okay so this option changes how every --files-from option that comes after it on the command line gets handled ๐Ÿ’…. Its effect gets undone by --no-verbatim-files-from.

The --null option implies this one, so you don't need to add it yourself when you're already using --null โœจ

Also check out --add-file for the related vibes ๐Ÿฆ‹

  • -X, --exclude-from=FILE โ€” Skip any files that match the patterns listed inside FILE ๐Ÿ™ˆ

๐ŸŒธ File name transformations

  • --strip-components=NUMBER โ€” Chop off NUMBER leading components from file names when you extract ๐Ÿ”ช
  • --transform=EXPRESSION, --xform=EXPRESSION โ€” Run a sed replace EXPRESSION to reshape file names into whatever look you want ๐Ÿ’–

๐Ÿงš File name matching options

These options affect both exclude and include patterns, so they're kind of a whole team ๐Ÿซถ

  • --anchored โ€” Patterns only match from the very start of a file name ๐Ÿ“Œ
  • --ignore-case โ€” Ignore case, no judgement ๐ŸŒˆ
  • --no-anchored โ€” Patterns can match after any /. This is the default for exclusion ๐Ÿ“
  • --no-ignore-case โ€” Matching is case sensitive. This is the default ๐Ÿ’…
  • --no-wildcards โ€” Verbatim string matching, no wildcard drama ๐Ÿฆ‹
  • --no-wildcards-match-slash โ€” Wildcards are not allowed to match / ๐Ÿšซ
  • --wildcards โ€” Use wildcards. This is the default for exclusion โœจ
  • --wildcards-match-slash โ€” Wildcards are allowed to match /. This is the default for exclusion ๐ŸŒธ

๐Ÿ“ฃ Informative output

  • --checkpoint[=N] โ€” Show a progress message every Nth record. The default is 10 ๐Ÿ“
  • --checkpoint-action=ACTION โ€” Run ACTION on each checkpoint ๐ŸŽฌ
  • --clamp-mtime โ€” Only set the time when the file is more recent than whatever you gave with --mtime ๐Ÿ•ฐ๏ธ
  • --full-time โ€” Print file times at their full resolution, no shortcuts ๐Ÿ•’
  • --index-file=FILE โ€” Send the verbose output over to FILE ๐Ÿ“‚
  • -l, --check-links โ€” Print a message if not all links got dumped ๐Ÿ”—
  • --no-quote-chars=STRING โ€” Turn off quoting for the characters in STRING ๐Ÿ™…โ€โ™€๏ธ
  • --quote-chars=STRING โ€” Also quote the characters in STRING ๐Ÿ’ฌ
  • --quoting-style=STYLE โ€” Set the 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 the block number within the archive alongside each message ๐Ÿ”ข
  • --show-omitted-dirs โ€” When listing or extracting, list every directory that doesn't match your search criteria ๐Ÿ“
  • --show-transformed-names, --show-stored-names โ€” Show file or archive names after they've been transformed by the --strip and --transform options ๐Ÿ‘€
  • --totals[=SIGNAL] โ€” Print the total bytes after processing the archive. If SIGNAL is given, print the total bytes when that signal gets 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 the files processed. Each time you use this option on the command line, the verbosity level goes up by one. The maximum verbosity level is 3. For a deep dive into how the different levels change tar's output, check out GNU Tar Manual, subsection 2.5.2 "The '--verbose' Option" ๐Ÿ“–
  • --warning=KEYWORD โ€” Enable or disable the warning messages identified by KEYWORD. The messages get suppressed if KEYWORD is prefixed with no-, and enabled otherwise โš ๏ธ
Multiple --warning options accumulate, so stack them as much as you want ๐Ÿ’œ

Here's the keyword breakdown, bestie ๐Ÿซถ

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 only applies if it's 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 the verbose description of failures that happen when tar tries to run alternative decompressor programs. This warning is disabled by default (unless --verbose is used). A common example of what you can get with this warning looks like:
$ tar --warning=decompress-program -x -f archive.Z
tar (child): cannot run compress: No such file or directory
tar (child): trying gzip

This means tar first tried to decompress archive.Z using compress, and when that failed, it 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 before every single action ๐Ÿคจ

๐ŸŽ€ Compatibility options

  • -o โ€” When creating, this is the same as --old-archive. When extracting, it's the 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 tells you whether it managed to pull off the requested operation, and if it didn't, what kind of error happened ๐Ÿ’€

  • 0 โ€” Successful termination. Slay โœจ
  • 1 โ€” Some files differ. If tar was invoked with the --compare (--diff, -d) command line option, this means 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 some files were changed while being archived, so the resulting archive does not contain the exact copy of the file set ๐Ÿ˜ฌ
  • 2 โ€” Fatal error. Some fatal, unrecoverable error happened ๐Ÿ˜ญ

If a subprocess that tar invoked exited with a nonzero exit code, tar itself exits with that code too. 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).

Want the full 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 ยฉ 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.


And that's a wrap on tar, bestie ๐ŸŽ€โœจ Thanks for sticking with me through all four parts! The TAR(1) page, dated July 11, 2022, is officially iconic ๐Ÿ‘‘๐Ÿ’–

๐Ÿ“ฆ where this page comes from