Introduction
Tar bundles files and folders into one file, keeping each file’s name, permissions,
owner and modification time. It began in Version 7 Unix in 1979 as a way to write files
to magnetic tape, which is why everything in it comes in 512-byte blocks. POSIX.1-1988
standardised it as the ustar format, and POSIX.1-2001 extended it as the pax format.
The two programs most people use today are
GNU tar, the tar of Linux,
and bsdtar from libarchive, the
tar of macOS, the BSDs and Windows.
Tar does not compress. A tar file is usually compressed as a whole afterwards, giving
.tar.gz or .tgz (gzip),
.tar.xz (xz),
.tar.bz2 (bzip2) and
.tar.zst (Zstandard). Tar is also found
inside other formats: Debian packages hold their files in tar archives, and container
images are made of tar layers.
Every tar header is a 512-byte block whose first 257 bytes, from the name to the link target, are the same in every tar format. What the rest of the block means is not. A version that only adds, such as new type flags or new pax records, stays in its format; a version that changes what existing header bytes mean is a separate format. That gives three tar formats: POSIX ustar and pax, GNU tar’s own, and Jörg Schilling’s star.
A tar file dropped on any page of this site opens in the explorer, which shows its structure: each member’s header field by field, its data, and the blocks that end the archive.
Variations
| Format | Variation | About | Open |
|---|---|---|---|
.TAR | POSIX ustar and pax archive | The POSIX header with “ustar” magic, owner names and a 155-byte prefix; pax adds records. | Open |
.TAR | GNU tar archive | GNU tar’s own header: times and sparse maps where ustar has the prefix, and long-name entries. | Open |
.TAR | Schily tar archive (star) | star’s header: a 131-byte prefix, with access and change times in the bytes after it. | Open |
An archive is the format of its first header. Bytes 257 to 264 of that header, the magic and version, tell GNU tar from the POSIX formats; star’s headers carry the POSIX magic, and are told apart by bytes 475 to 511.
| Format | Bytes 257 to 264 | Bytes 345 to 511 |
|---|---|---|
| POSIX ustar and pax | ustar\0 00, or zeros in Version 7 | a 155-byte name prefix, then 12 unused bytes |
| GNU tar | ustar, two spaces, \0 | access and change times, a volume offset, sparse map entries and a real size |
| star | ustar\0 00 | a 131-byte prefix, access and change times, and tar\0 at 508 in xstar |
POSIX ustar and pax archive
The standard tar format, written by bsdtar, Python, Go and most libraries, and by GNU tar when asked. It covers three generations, because each only adds to the one before: the Version 7 header of 1979, whose bytes after 257 are unused; POSIX.1-1988 ustar, which puts a magic, owner names, device numbers and a 155-byte path prefix in those bytes; and POSIX.1-2001 pax, which keeps the ustar header and adds extended headers of key and value records for long names, large sizes and exact times.
Bytes 257 to 262 are ustar\0 (75 73 74 61 72 00) and 263
to 264 are 00, or, in a Version 7 archive, all of them are zero; and the
header has neither star’s signature nor star’s time fields.
GNU tar archive
GNU tar’s own format, which it writes by default. It is older than the ustar
standard and not compatible with it: where ustar has the path prefix, the GNU header
has access and change times, a multi-volume offset, four sparse map entries and the
real size of a sparse file. Long names go in L and K entries
before the member, and incremental backups, sparse files and multi-volume archives
have type flags of their own.
Bytes 257 to 264 are ustar, two spaces and a NUL
(75 73 74 61 72 20 20 00).
Schily tar archive (star)
The format of star, Jörg Schilling’s tar. Its header has the POSIX magic and
version, but cuts the 155-byte prefix to 131 bytes and puts the access and change
times in the 24 bytes freed, which a ustar reader takes as part of the prefix. In the
xstar form it ends with the signature tar\0 at byte 508; the later xustar
form leaves it out, and exustar adds pax headers.
Bytes 257 to 264 are ustar\0 00, and either bytes 508 to
511 are tar\0, or byte 475 is zero and bytes 476 to 499 hold two
times, each 11 octal digits and a space or NUL, or in base-256.
Versions
The releases that changed what tar files look like, with the format each writes. GNU tar dates are those of its files on ftp.gnu.org.
| Date | Release | Format written |
|---|---|---|
| January 1979 | Version 7 Unix: the first tar, replacing tp | POSIX ustar and pax (the Version 7 header) |
| 1985 | star’s first full version, with star’s first header extensions | star’s 1985 header, the tar\0 signature at 508 and no ustar magic |
| 29 October 1986 | pdtar, John Gilmore’s public-domain tar | a draft of the POSIX header: GNU tar’s magic with a name prefix at 345 |
| About 1988 | GNU tar begins, from pdtar | GNU tar |
| 1988 | POSIX.1-1988 (IEEE Std 1003.1-1988) defines ustar | POSIX ustar and pax |
| 1994 | star adds the POSIX.1-1988 header and defines its xstar header | star |
| 1 October 1996 | GNU tar 1.11.8, the oldest full release on ftp.gnu.org | GNU tar (the flavour GNU tar now calls oldgnu) |
| 26 April 1997 | GNU tar 1.12 | GNU tar (oldgnu) |
| 8 July 1999 | GNU tar 1.13, the start of the gnu flavour | GNU tar |
| 2001 | POSIX.1-2001 (IEEE Std 1003.1-2001) adds the pax format | POSIX ustar and pax |
| 11 May 2004 | GNU tar 1.14, which can write POSIX.1-2001 archives | GNU tar by default; pax with --format=posix |
| 2004 | libarchive and bsdtar; their tar(5) manual page is dated 20 May 2004 (the first release year is not confirmed) | POSIX ustar and pax |
| 2009 | Mac OS X 10.6 makes bsdtar its tar | POSIX ustar and pax |
| 2018 | Windows 10 version 1803 includes bsdtar | POSIX ustar and pax |
| 18 July 2023 | GNU tar 1.35, the latest release | GNU tar |
| 2024 | IEEE Std 1003.1-2024 (POSIX Issue 8), with the same ustar and pax formats | POSIX ustar and pax |
GNU tar’s manual says its default format is set when it is built, is usually
gnu, and that posix will be the default in a future
version. The oldgnu and gnu flavours write the same magic
and header layout, so they are one format here.
Structure
In every tar format a file is a sequence of 512-byte blocks. Each member is a header block describing it, followed by its contents, padded with zeros to a whole number of blocks. A folder, a link or a device is a header with no contents. Two blocks of zeros end the archive.
0Header name, mode, owner, size, time, checksum, type512 bytes512File data the file’s bytes, padded with zeros to a multiple of 512size rounded up…Next header and its data, for each further memberrepeated…End of archive two blocks of zeros, then often padding to a whole record1024 bytes or more
There is no index. To list an archive, a reader reads each header, uses the size in it to skip over the member’s data, and reads the next header. Details that the header cannot hold go in extra members before the one they describe: pax extended headers in the POSIX format and star’s, long-name entries in GNU tar’s.
Multi-volume sets and sparse files in the viewer
A file that does not fit on one volume of a multi-volume archive is cut short at the end
of the volume and carried on by a type M member at the start of the next. In
GNU tar’s header (tar.h, src/buffer.c) the M
member’s size is what is left of the file, and the offset at byte 369 is what was already
written, so the two add up to the whole file; with --format=posix the part is an ordinary member named
…/GNUFileParts.pid/name.n, after a global header with
GNU.volume.filename, GNU.volume.size and GNU.volume.offset.
tar has no rule for naming volumes, so the explorer recognises them by what they hold: dropped
together (a folder, or several files) the volumes that continue each other are joined in order,
the volumes are listed, and every part of a split file opens as the whole file. A volume that is not
handed over leaves the file unopened and the gap is named.
A sparse file (GNU or star, in the header or in pax records 0.0, 0.1 and 1.0) is stored as its
stretches of data and a map; the viewer puts the holes back and opens the file whole, however large
its real size: a file over 16 MiB is made on demand, range by range, so no part of it is out of reach.
Lines starting with # in a 1.0 map, which GNU tar does not write, are skipped as libarchive does.
The six GNU sparse archives of libarchive’s test suite (old GNU, 1.17, pax 0.0, 0.1, 1.0 and the 1.0 form with comment lines) rebuild to the same
bytes as bsdtar’s extraction.
Not described
Known, not yet covered
- Viewer: a file that is both sparse and split over volumes is shown part by part; its parts are not joined.
- Viewer: the join recognises the continuation of a star archive by its offset and real size as it does GNU tar’s, but no star multi-volume set was found to try it on.
Unknown
- Reference and viewer: whether real archives of star’s sparse form, of the multi-volume headers
(
M,V, and the paxGNU.volumeform), of star’s 1985 header and pdtar, and of SolarisEentries read the way the archives built from the sources do: none was found, and GNU tar and star are not installed to write one. Real GNU tar sparse archives, Solaris tar archives with ACLs and star archives with ACLs do read. - Reference and viewer: the layout of AIX’s coded access-control
list (type
A), which IBM has not published. Shown as labelled bytes.
Links
Software
- GNU tar – the GNU
tarcommand, standard on Linux; writes GNU format by default and reads all three (Linux, macOS, Windows) - bsdtar – libarchive’s
tar, the one on macOS, the BSDs and Windows 10 1803 and later; writes ustar and pax (macOS, Windows, Linux) - star – Jörg Schilling’s tar, in the schilytools collection; writes star’s formats, ustar and pax (Unix-like systems)
- 7-Zip – free archiver that opens and makes tar files (Windows)
- WinRAR – archiver that extracts tar files (Windows)
- PeaZip – free archiver for many formats (Windows, macOS, Linux)
- Archive Utility – the Mac’s built-in extractor, which opens tar files (macOS)
Developers
- libarchive – library that reads every tar format and writes ustar, pax and others (C)
- tarfile – standard library module for ustar, GNU and pax archives (Python)
- archive/tar – standard library package that reads Version 7, ustar, pax, GNU and star archives (Go)
- node-tar – the tar library npm uses (JavaScript)
- tar-stream – streaming tar reader and writer (JavaScript)
- tar-rs – the
tarcrate (Rust) - Apache Commons Compress – archive and compression library with tar support (Java)
Reference
- pax – the POSIX description of the ustar and pax formats (IEEE Std 1003.1-2024)
- Basic Tar Format – the GNU tar manual’s description of its headers, with GNU tar’s
tar.h - Controlling the Archive Format – the GNU tar manual on the formats it reads and writes
- tar(5) – libarchive’s description of every tar variant and its history
- star(5) – star’s description of its header formats