TAR(1)
๐ 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-recursionoption ๐ณ-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 status0. When you give one or more command line arguments, tar compares the volume label against each argument. It exits with code0if it finds a match, and with code1otherwise. 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-cand-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 ๐ธFILEis 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. IfFILEdoesn'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 asFILE๐ง
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โ useMETHODto detect holes in sparse files ๐ณ๏ธ This option implies--sparse. The valid values forMETHODareseekandraw. The default isseek, with a fallback torawwhenseekisn'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=0actually 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--listor--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,--extractor--list, and only when a list of files is given either on the command line or via the-Toption. The defaultNis1.--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 are0.0,0.1and1.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 intoDIR. 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-compressrecognizes 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 intoCOMMAND. 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]โ ForceNAMEas the group for added files. IfGIDisn't supplied,NAMEcan 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 fromFILE. Empty lines get ignored. Comments start with a#sign and run to the end of the line. Each non-empty line inFILEdefines 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 modeCHANGESonto added files ๐จ--mtime=DATE-OR-FILEโ Set the mtime for added files.DATE-OR-FILEis 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-restoreoption ๐ โโ๏ธ--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]โ ForceNAMEas the owner for added files. IfUIDisn't supplied,NAMEcan 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 fromFILE. Empty lines get ignored. Comments start with a#sign and run to the end of the line. Each non-empty line inFILEdefines 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 toORDER, which is one ofnone,name, orinode๐๏ธ
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.PATTERNis 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.PATTERNis a globbing pattern ๐ฏ
โจ Device selection and switching โจ
Picking where your archive lives, and letting it travel ๐งโจ
-f,--file=ARCHIVEโ Use the archive file or deviceARCHIVE. If you don't give this option, tar first checks the environment variableTAPE. 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-defaultsoption, or at the end of thetar --helpoutput ๐
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โ runsCOMMANDat 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 writingNx1024 bytes ๐ผ IfNhas 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โ usesCOMMANDinstead ofrmtwhen accessing remote archives ๐ฐ๏ธ See the description of the-foption, above.--rsh-command=COMMANDโ usesCOMMANDinstead ofrshwhen accessing remote archives ๐ See the description of the-foption, 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 inFILE๐งพ
โจ Device blocking โจ
-b,--blocking-factor=BLOCKSโ sets the record size toBLOCKSx512 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-Aoption.--record-size=NUMBERโ sets the record size ๐NUMBERis the number of bytes per record, and it must be a multiple of 512. You can add a size suffix, like--record-size=10Kfor 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 formatoldgnuโ GNU format as per tar <= 1.12pax,posixโ POSIX 1003.1-2001 (pax) formatustarโ POSIX 1003.1-1988 (ustar) formatv7โ 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-ooption of thepax(1)utility.--posixโ same as--format=posix๐ฎ-V,--label=TEXTโ creates an archive with the volume nameTEXT๐ท๏ธ When listing or extracting,TEXTis 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 throughCOMMAND๐ง It must accept the-doption (for decompression), and the argument can include command line options.-j,--bzip2โ filters the archive throughbzip2(1)๐-J,--xzโ filters the archive throughxz(1)๐--lzipโ filters the archive throughlzip(1)๐--lzmaโ filters the archive throughlzma(1)๐--lzopโ filters the archive throughlzop(1)๐ซง--no-auto-compressโ don't use the archive suffix to pick the compression program ๐ โโ๏ธ-z,--gzip,--gunzip,--ungzipโ filters the archive throughgzip(1)๐ญ-Z,--compress,--uncompressโ filters the archive throughcompress(1)๐ซ--zstdโ filters the archive throughzstd(1)โก
๐ Local file selection ๐
--add-file=FILEโ addsFILEto the archive. Super useful if its name starts with a dash ๐ชฝ--backup[=CONTROL]โ makes a backup before removal ๐ TheCONTROLargument, 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 toDIRbefore doing anything else ๐ This option is order-sensitive, meaning it affects all the options that come after it.--exclude=PATTERNโ excludes files matchingPATTERN, a glob(3)-style wildcard pattern ๐ท--exclude-backupsโ excludes backup and lock files ๐--exclude-cachesโ excludes the contents of directories containing the fileCACHEDIR.TAG, except for the tag file itself ๐๏ธ--exclude-caches-allโ excludes directories containing the fileCACHEDIR.TAG, along with the file itself ๐--exclude-caches-underโ excludes everything under directories containingCACHEDIR.TAG๐--exclude-ignore=FILEโ before dumping a directory, checks whether it containsFILE. 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 fromFILEaffect both the directory and all of its subdirectories ๐ณ--exclude-tag=FILEโ excludes the contents of directories containingFILE, except forFILEitself ๐ท๏ธ--exclude-tag-all=FILEโ excludes directories containingFILE๐ช--exclude-tag-under=FILEโ excludes everything under directories containingFILE๐งน--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 afterDATE๐ IfDATEstarts 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--nulloption ๐ โโ๏ธ--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-Toptions 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 thanDATE๐๏ธ IfDATEstarts 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 theSIMPLE_BACKUP_SUFFIXenvironment variable.-T,--files-from=FILEโ gets the names to extract or create fromFILE๐
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-fromoption 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 areliteral,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--stripand--transformoptions ๐--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, andSIGUSR2. TheSIGprefix 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 withno-, 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-readoption ๐
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--verboseis 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,--appendor--updateoptions, 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 ๐
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
- alpine 3.22: tar-doc 1.35-r3 ยท GPL-3.0-or-later
- alpine 3.23: tar-doc 1.35-r4 ยท GPL-3.0-or-later
- alpine 3.24: tar-doc 1.35-r5 ยท GPL-3.0-or-later
- arch rolling: tar 1.35-5 ยท GPL-3.0-or-later
- centos-stream 10: tar 2:1.35-13.el10 ยท GPL-3.0-or-later
- debian trixie: tar 1.35+dfsg-3.1 ยท GPL-3.0-or-later
- fedora 43: tar 2:1.35-6.fc43 ยท GPL-3.0-or-later
- fedora 44: tar 2:1.35-8.fc44 ยท GPL-3.0-or-later
- fedora 44: tar 2:1.35-9.fc44 ยท GPL-3.0-or-later
- nixos 26.05: gnutar 1.35
- nixos 26.05: gnutar-static 1.35
- nixpkgs unstable: gnutar 1.35
- opensuse-leap 16.0: tar 1.35-160000.5.1 ยท GPL-3.0-or-later
- opensuse-leap 16.0: tar 1.35-160000.5.1 ยท GPL-3.0-or-later
- opensuse-leap 16.0: tar 1.35-160000.5.1 ยท GPL-3.0-or-later
- opensuse-leap 16.0: tar 1.35-160000.5.1 ยท GPL-3.0-or-later
- ubuntu noble: tar 1.35+dfsg-3build1 ยท GPL-3.0-or-later
- ubuntu noble: tar 1.35+dfsg-3ubuntu0.4 ยท GPL-3.0-or-later
- ubuntu questing: tar 1.35+dfsg-3.1build1 ยท GPL-3.0-or-later
- ubuntu resolute: tar 1.35+dfsg-4 ยท GPL-3.0-or-later
- ubuntu resolute: tar 1.35+dfsg-4ubuntu0.4 ยท GPL-3.0-or-later
- ubuntu stonking: tar 1.35+dfsg-5ubuntu1 ยท GPL-3.0-or-later
- Copyright 2013-2023 Free Software Foundation, Inc
- ๐ girlified by anthropic/claude-haiku-5.5 on : a language model's rewrite of the original, under its terms