1 .TH TAR 5 "December 27, 2016" ""
5 \- format of tape archive files
10 archive format collects any number of files, directories, and other
11 file system objects (symbolic links, device nodes, etc.) into a single
13 The format was originally designed to be used with
14 tape drives that operate with fixed-size blocks, but is widely used as
15 a general packaging mechanism.
19 archive consists of a series of 512-byte records.
20 Each file system object requires a header record which stores basic metadata
21 (pathname, owner, permissions, etc.) and zero or more records containing any
23 The end of the archive is indicated by two records consisting
24 entirely of zero bytes.
26 For compatibility with tape drives that use fixed block sizes,
27 programs that read or write tar files always read or write a fixed
28 number of records with each I/O operation.
31 are always a multiple of the record size.
32 The maximum block size supported by early
33 implementations was 10240 bytes or 20 records.
34 This is still the default for most implementations
35 although block sizes of 1MiB (2048 records) or larger are
36 commonly used with modern high-speed tape drives.
41 here are not entirely standard; this document follows the
42 convention established by John Gilmore in documenting
44 .SS Old-Style Archive Format
45 The original tar archive format has been extended many times to
46 include additional information that various implementors found
48 This section describes the variant implemented by the tar command
51 which seems to be the earliest widely-used version of the tar program.
53 The header record for an old-style
55 archive consists of the following:
58 struct header_old_tar {
71 All unused bytes in the header record are filled with nulls.
75 Pathname, stored as a null-terminated string.
76 Early tar implementations only stored regular files (including
77 hardlinks to those files).
78 One common early convention used a trailing "/" character to indicate
79 a directory name, allowing directory permissions and owner information
80 to be archived and restored.
83 File mode, stored as an octal number in ASCII.
86 User id and group id of owner, as octal numbers in ASCII.
89 Size of file, as octal number in ASCII.
90 For regular files only, this indicates the amount of data
91 that follows the header.
92 In particular, this field was ignored by early tar implementations
93 when extracting hardlinks.
94 Modern writers should always store a zero length for hardlink entries.
97 Modification time of file, as an octal number in ASCII.
98 This indicates the number of seconds since the start of the epoch,
99 00:00:00 UTC January 1, 1970.
100 Note that negative values should be avoided
101 here, as they are handled inconsistently.
104 Header checksum, stored as an octal number in ASCII.
105 To compute the checksum, set the checksum field to all spaces,
106 then sum all bytes in the header using unsigned arithmetic.
107 This field should be stored as six octal digits followed by a null and a space
109 Note that many early implementations of tar used signed arithmetic
110 for the checksum field, which can cause interoperability problems
111 when transferring archives between systems.
112 Modern robust readers compute the checksum both ways and accept the
113 header if either computation matches.
115 \fIlinkflag\fP, \fIlinkname\fP
116 In order to preserve hardlinks and conserve tape, a file
117 with multiple links is only written to the archive the first
118 time it is encountered.
119 The next time it is encountered, the
125 field holds the first name under which this file appears.
126 (Note that regular files have a null value in the
131 Early tar implementations varied in how they terminated these fields.
134 used the following conventions (this is also documented in early BSD manpages):
135 the pathname must be null-terminated;
136 the mode, uid, and gid fields must end in a space and a null byte;
137 the size and mtime fields must end in a space;
138 the checksum is terminated by a null and a space.
139 Early implementations filled the numeric fields with leading spaces.
140 This seems to have been common practice until the
141 IEEE Std 1003.1-1988 (``POSIX.1'')
142 standard was released.
143 For best portability, modern implementations should fill the numeric
144 fields with leading zeros.
145 .SS Pre-POSIX Archives
147 IEEE Std 1003.1-1988 (``POSIX.1'')
148 served as the basis for John Gilmore's
150 program and many system implementations from the late 1980s
152 These archives generally follow the POSIX ustar
153 format described below with the following variations:
156 The magic value consists of the five characters
159 The version field contains a space character followed by a null.
161 The numeric fields are generally filled with leading spaces
162 (not leading zeros as recommended in the final standard).
164 The prefix field is often not used, limiting pathnames to
165 the 100 characters of old-style archives.
167 .SS POSIX ustar Archives
168 IEEE Std 1003.1-1988 (``POSIX.1'')
169 defined a standard tar file format to be read and written
170 by compliant implementations of
172 This format is often called the
174 format, after the magic value used
176 (The name is an acronym for
177 ``Unix Standard TAR''.)
178 It extends the historic format with new fields:
181 struct header_posix_ustar {
205 POSIX extended the earlier
207 field with several new type values:
212 NUL should be treated as a synonym, for compatibility purposes.
221 Character device node.
236 A POSIX-compliant implementation must treat any unrecognized typeflag value
238 In particular, writers should ensure that all entries
239 have a valid filename so that they can be restored by readers that do not
240 support the corresponding extension.
241 Uppercase letters "A" through "Z" are reserved for custom extensions.
242 Note that sockets and whiteout entries are not archivable.
244 It is worth noting that the
246 field, in particular, has different meanings depending on the type.
247 For regular files, of course, it indicates the amount of data
248 following the header.
249 For directories, it may be used to indicate the total size of all
250 files in the directory, for use by operating systems that pre-allocate
252 For all other types, it should be set to zero by writers and ignored
256 Contains the magic value
258 followed by a NUL byte to indicate that this is a POSIX standard archive.
259 Full compliance requires the uname and gname fields be properly set.
265 (two copies of the ASCII digit zero) for POSIX standard archives.
267 \fIuname\fP, \fIgname\fP
268 User and group names, as null-terminated ASCII strings.
269 These should be used in preference to the uid/gid values
270 when they are set and the corresponding names exist on
273 \fIdevmajor\fP, \fIdevminor\fP
274 Major and minor numbers for character device or block device entry.
276 \fIname\fP, \fIprefix\fP
277 If the pathname is too long to fit in the 100 bytes provided by the standard
278 format, it can be split at any
280 character with the first portion going into the prefix field.
281 If the prefix field is not empty, the reader will prepend
282 the prefix value and a
284 character to the regular name field to obtain the full pathname.
285 The standard does not require a trailing
287 character on directory names, though most implementations still
288 include this for compatibility reasons.
291 Note that all unused bytes must be set to
294 Field termination is specified slightly differently by POSIX
295 than by previous implementations.
301 fields must have a trailing
308 fields must have a trailing
310 unless they fill the entire field.
311 (In particular, it is possible to store a 256-character pathname if it
314 as the 156th character.)
315 POSIX requires numeric fields to be zero-padded in the front, and requires
316 them to be terminated with either space or
320 Currently, most tar implementations comply with the ustar
321 format, occasionally extending it by adding new fields to the
322 blank area at the end of the header record.
323 .SS Numeric Extensions
324 There have been several attempts to extend the range of sizes
325 or times supported by modifying how numbers are stored in the
328 One obvious extension to increase the size of files is to
329 eliminate the terminating characters from the various
331 For example, the standard only allows the size field to contain
332 11 octal digits, reserving the twelfth byte for a trailing
334 Allowing 12 octal digits allows file sizes up to 64 GB.
336 Another extension, utilized by GNU tar, star, and other newer
338 implementations, permits binary numbers in the standard numeric fields.
339 This is flagged by setting the high bit of the first byte.
340 The remainder of the field is treated as a signed twos-complement
342 This permits 95-bit values for the length and time fields
343 and 63-bit values for the uid, gid, and device numbers.
344 In particular, this provides a consistent way to handle
345 negative time values.
346 GNU tar supports this extension for the
347 length, mtime, ctime, and atime fields.
348 Joerg Schilling's star program and the libarchive library support
349 this extension for all numeric fields.
350 Note that this extension is largely obsoleted by the extended
351 attribute record provided by the pax interchange format.
353 Another early GNU extension allowed base-64 values rather than octal.
354 This extension was short-lived and is no longer supported by any
356 .SS Pax Interchange Format
357 There are many attributes that cannot be portably stored in a
359 IEEE Std 1003.1-2001 (``POSIX.1'')
361 ``pax interchange format''
362 that uses two new types of entries to hold text-formatted
363 metadata that applies to following entries.
364 Note that a pax interchange format archive is a ustar archive in every
366 The new data is stored in ustar-compatible archive entries that use the
371 In particular, older implementations that do not fully support these
372 extensions will extract the metadata into regular files, where the
373 metadata can be examined as necessary.
375 An entry in a pax interchange format archive consists of one or
376 two standard ustar entries, each with its own header and data.
377 The first optional entry stores the extended attributes
378 for the following entry.
379 This optional first entry has an "x" typeflag and a size field that
380 indicates the total size of the extended attributes.
381 The extended attributes themselves are stored as a series of text-format
382 lines encoded in the portable UTF-8 encoding.
383 Each line consists of a decimal number, a space, a key string, an equals
384 sign, a value string, and a new line.
385 The decimal number indicates the length of the entire line, including the
386 initial length field and the trailing newline.
387 An example of such a field is:
389 25 ctime=1084839148.1212\en
391 Keys in all lowercase are standard keys.
392 Vendors can add their own keys by prefixing them with an all uppercase
393 vendor name and a period.
394 Note that, unlike the historic header, numeric values are stored using
396 A description of some common keys follows:
399 \fBatime\fP, \fBctime\fP, \fBmtime\fP
400 File access, inode change, and modification times.
401 These fields can be negative or include a decimal point and a fractional value.
404 The character set used by the pax extension values.
405 By default, all textual values in the pax extended attributes
406 are assumed to be in UTF-8, including pathnames, user names,
408 In some cases, it is not possible to translate local
409 conventions into UTF-8.
410 If this key is present and the value is the six-character ASCII string
412 then all textual values are assumed to be in a platform-dependent
414 Note that there are only two valid values for this key:
417 ``ISO-IR\ 10646\ 2000\ UTF-8''.
418 No other values are permitted by the standard, and
419 the latter value should generally not be used as it is the
420 default when this key is not specified.
421 In particular, this flag should not be used as a general
422 mechanism to allow filenames to be stored in arbitrary
425 \fBuname\fP, \fBuid\fP, \fBgname\fP, \fBgid\fP
426 User name, group name, and numeric UID and GID values.
427 The user name and group name stored here are encoded in UTF8
428 and can thus include non-ASCII characters.
429 The UID and GID fields can be of arbitrary length.
432 The full path of the linked-to file.
433 Note that this is encoded in UTF8 and can thus include non-ASCII characters.
436 The full pathname of the entry.
437 Note that this is encoded in UTF8 and can thus include non-ASCII characters.
439 \fBrealtime.*\fP, \fBsecurity.*\fP
440 These keys are reserved and may be used for future standardization.
443 The size of the file.
444 Note that there is no length limit on this field, allowing conforming
445 archives to store files much larger than the historic 8GB limit.
448 Vendor-specific attributes used by Joerg Schilling's
452 \fBSCHILY.acl.access\fP, \fBSCHILY.acl.default,\fP \fBSCHILY.acl.ace\fP
453 Stores the access, default and NFSv4 ACLs as textual strings in a format
454 that is an extension of the format specified by POSIX.1e draft 17.
455 In particular, each user or group access specification can include
456 an additional colon-separated field with the numeric UID or GID.
457 This allows ACLs to be restored on systems that may not have complete
458 user or group information available (such as when NIS/YP or LDAP services
459 are temporarily unavailable).
461 \fBSCHILY.devminor\fP, \fBSCHILY.devmajor\fP
462 The full minor and major numbers for device nodes.
467 \fBSCHILY.realsize\fP
468 The full size of the file on disk.
471 \fBSCHILY.dev,\fP \fBSCHILY.ino\fP, \fBSCHILY.nlinks\fP
472 The device number, inode number, and link count for the entry.
473 In particular, note that a pax interchange format archive using Joerg
476 extensions can store all of the data from
480 Vendor-specific attributes used by the
482 library and programs that use it.
484 \fBLIBARCHIVE.creationtime\fP
485 The time when the file was created.
486 (This should not be confused with the POSIX
488 attribute, which refers to the time when the file
489 metadata was last changed.)
491 \fBLIBARCHIVE.xattr.\fP \fInamespace\fP.\fIkey\fP
492 Libarchive stores POSIX.1e-style extended attributes using
496 value is URL-encoded:
497 All non-ASCII characters and the two special characters
503 followed by two uppercase hexadecimal digits.
504 The value of this key is the extended attribute value
506 XXX Detail the base-64 format here XXX
509 XXX document other vendor-specific extensions XXX
512 Any values stored in an extended attribute override the corresponding
513 values in the regular tar header.
514 Note that compliant readers should ignore the regular fields when they
516 This is important, as existing archivers are known to store non-compliant
517 values in the standard header fields in this situation.
518 There are no limits on length for any of these fields.
519 In particular, numeric fields can be arbitrarily large.
520 All text fields are encoded in UTF8.
521 Compliant writers should store only portable 7-bit ASCII characters in
522 the standard ustar header and use extended
523 attributes whenever a text value contains non-ASCII characters.
527 entry described above, the pax interchange format
533 entry is identical in format, but specifies attributes that serve as
534 defaults for all subsequent archive entries.
537 entry is not widely used.
543 entries, the pax interchange format has a few other minor variations
544 from the earlier ustar format.
545 The most troubling one is that hardlinks are permitted to have
547 This allows readers to restore any hardlink to a file without
548 having to rewind the archive to find an earlier entry.
549 However, it creates complications for robust readers, as it is no longer
550 clear whether or not they should ignore the size field for hardlink entries.
552 The GNU tar program started with a pre-POSIX format similar to that
553 described earlier and has extended it using several different mechanisms:
554 It added new fields to the empty space in the header (some of which was later
555 used by POSIX for conflicting purposes);
556 it allowed the header to be continued over multiple records;
557 and it defined new entries that modify following entries
558 (similar in principle to the
560 entry described above, but each GNU special entry is single-purpose,
561 unlike the general-purpose
564 As a result, GNU tar archives are not POSIX compatible, although
565 more lenient POSIX-compliant readers can successfully extract most
569 struct header_gnu_tar {
602 GNU tar uses the following special entry types, in addition to
603 those defined by POSIX:
607 GNU tar treats type "7" records identically to type "0" records,
608 except on one obscure RTOS where they are used to indicate the
609 pre-allocation of a contiguous file on disk.
612 This indicates a directory entry.
613 Unlike the POSIX-standard "5"
614 typeflag, the header is followed by data records listing the names
615 of files in this directory.
616 Each name is preceded by an ASCII "Y"
617 if the file is stored in this archive or "N" if the file is not
618 stored in this archive.
619 Each name is terminated with a null, and
620 an extra null marks the end of the name list.
622 entry is to support incremental backups; a program restoring from
623 such an archive may wish to delete files on disk that did not exist
624 in the directory when the archive was made.
626 Note that the "D" typeflag specifically violates POSIX, which requires
627 that unrecognized typeflags be restored as normal files.
628 In this case, restoring the "D" entry as a file could interfere
629 with subsequent creation of the like-named directory.
632 The data for this entry is a long linkname for the following regular entry.
635 The data for this entry is a long pathname for the following regular entry.
638 This is a continuation of the last file on the previous volume.
639 GNU multi-volume archives guarantee that each volume begins with a valid
641 To ensure this, a file may be split, with part stored at the end of one volume,
642 and part stored at the beginning of the next volume.
643 The "M" typeflag indicates that this entry continues an existing file.
644 Such entries can only occur as the first or second entry
645 in an archive (the latter only if the first entry is a volume label).
648 field specifies the size of this entry.
651 field at bytes 369-380 specifies the offset where this file fragment
655 field specifies the total size of the file (which must equal
659 When extracting, GNU tar checks that the header file name is the one it is
660 expecting, that the header offset is in the correct sequence, and that
661 the sum of offset and size is equal to realsize.
664 Type "N" records are no longer generated by GNU tar.
666 list of files to be renamed or symlinked after extraction; this was
667 originally used to support long names.
668 The contents of this record
669 are a text description of the operations to be done, in the form
670 ``Rename %s to %s\en''
672 ``Symlink %s to %s\en ;''
674 filenames are escaped using K&R C syntax.
675 Due to security concerns, "N" records are now generally ignored
676 when reading archives.
682 Sparse files are stored as a series of fragments.
683 The header contains a list of fragment offset/length pairs.
684 If more than four such entries are required, the header is
685 extended as necessary with
687 header extensions (an older format that is no longer used), or
694 field should be interpreted as a tape/volume header name.
695 This entry should generally be ignored on extraction.
699 The magic field holds the five characters
702 Note that POSIX ustar archives have a trailing null.
705 The version field holds a space character followed by a null.
706 Note that POSIX ustar archives use two copies of the ASCII digit
709 \fIatime\fP, \fIctime\fP
710 The time the file was last accessed and the time of
711 last change of file information, stored in octal as with
715 This field is apparently no longer used.
717 Sparse \fIoffset\fP / \fInumbytes\fP
718 Each such structure specifies a single fragment of a sparse
720 The two fields store values as octal numbers.
721 The fragments are each padded to a multiple of 512 bytes
723 On extraction, the list of fragments is collected from the
724 header (including any extension headers), and the data
725 is then read and written to the file at appropriate offsets.
728 If this is set to non-zero, the header will be followed by additional
731 Each such record contains information about as many as 21 additional
732 sparse blocks as shown here:
735 struct gnu_sparse_header {
746 A binary representation of the file's complete size, with a much larger range
747 than the POSIX file size.
750 type files, the current entry is only a portion of the file.
751 In that case, the POSIX size field will indicate the size of this
754 field will indicate the total size of the file.
756 .SS GNU tar pax archives
757 GNU tar 1.14 (XXX check this XXX) and later will write
758 pax interchange format archives when you specify the
761 This format follows the pax interchange format closely,
764 tags and introducing new keywords to store sparse file information.
765 There have been three iterations of the sparse file support, referred to
773 \fBGNU.sparse.numblocks\fP, \fBGNU.sparse.offset\fP, \fBGNU.sparse.numbytes\fP, \fBGNU.sparse.size\fP
776 format used an initial
777 \fBGNU.sparse.numblocks\fP
778 attribute to indicate the number of blocks in the file, a pair of
779 \fBGNU.sparse.offset\fP
781 \fBGNU.sparse.numbytes\fP
782 to indicate the offset and size of each block,
784 \fBGNU.sparse.size\fP
785 to indicate the full size of the file.
786 This is not the same as the size in the tar header because the
787 latter value does not include the size of any holes.
788 This format required that the order of attributes be preserved and
789 relied on readers accepting multiple appearances of the same attribute
790 names, which is not officially permitted by the standards.
795 format used a single attribute that stored a comma-separated
796 list of decimal numbers.
797 Each pair of numbers indicated the offset and size, respectively,
799 This does not work well if the archive is extracted by an archiver
800 that does not recognize this extension, since many pax implementations
801 simply discard unrecognized attributes.
803 \fBGNU.sparse.major\fP, \fBGNU.sparse.minor\fP, \fBGNU.sparse.name\fP, \fBGNU.sparse.realsize\fP
806 format stores the sparse block map in one or more 512-byte blocks
807 prepended to the file data in the entry body.
808 The pax attributes indicate the existence of this map
810 \fBGNU.sparse.major\fP
812 \fBGNU.sparse.minor\fP
814 and the full size of the file.
816 \fBGNU.sparse.name\fP
817 holds the true name of the file.
818 To avoid confusion, the name stored in the regular tar header
819 is a modified name so that extraction errors will be apparent
823 XXX More Details Needed XXX
825 Solaris tar (beginning with SunOS XXX 5.7 ?? XXX) supports an
827 format that is fundamentally similar to pax interchange format,
828 with the following differences:
831 Extended attributes are stored in an entry whose type is
835 as used by pax interchange format.
836 The detailed format of this entry appears to be the same
837 as detailed above for the
843 header is used to store an ACL for the following regular entry.
844 The body of this entry contains a seven-digit octal number
845 followed by a zero byte, followed by the
846 textual ACL description.
847 The octal value is the number of ACL entries
848 plus a constant that indicates the ACL type: 01000000
849 for POSIX.1e ACLs and 03000000 for NFSv4 ACLs.
852 XXX More details needed XXX
854 AIX Tar uses a ustar-formatted header with the type
856 for storing coded ACL information.
857 Unlike the Solaris format, AIX tar writes this header after the
858 regular file body to which it applies.
859 The pathname in this header is either
863 to indicate the type of ACL stored.
864 The actual ACL is stored in platform-specific binary format.
866 The tar distributed with Apple's Mac OS X stores most regular files
867 as two separate files in the tar archive.
868 The two files have the same name except that the first
871 prepended to the last path element.
872 This special file stores an AppleDouble-encoded
873 binary blob with additional metadata about the second file,
874 including ACL, extended attributes, and resources.
875 To recreate the original file on disk, each
876 separate file can be extracted and the Mac OS X
878 function can be used to unpack the separate
879 metadata file and apply it to th regular file.
880 Conversely, the same function provides a
882 option to encode the extended metadata from
883 a file into a separate file whose contents
884 can then be put into a tar archive.
886 Note that the Apple extended attributes interact
887 badly with long filenames.
888 Since each file is stored with the full name,
889 a separate set of extensions needs to be included
890 in the archive for each one, doubling the overhead
891 required for files with long names.
892 .SS Summary of tar type codes
893 The following list is a condensed summary of the type codes
894 used in tar header records generated by different tar implementations.
895 More details about specific implementations can be found above:
899 Early tar programs stored a zero byte for regular files.
902 POSIX standard type code for a regular file.
905 POSIX standard type code for a hard link description.
908 POSIX standard type code for a symbolic link description.
911 POSIX standard type code for a character device node.
914 POSIX standard type code for a block device node.
917 POSIX standard type code for a directory.
920 POSIX standard type code for a FIFO.
926 GNU tar used for pre-allocated files on some systems.
929 Solaris tar ACL description stored prior to a regular file header.
932 AIX tar ACL description stored after the file body.
935 GNU tar directory dump.
938 GNU tar long linkname for the following header.
941 GNU tar long pathname for the following header.
944 GNU tar multivolume marker, indicating the file is a continuation of a file from the previous volume.
947 GNU tar long filename support. Deprecated.
950 GNU tar sparse regular file.
953 GNU tar tape/volume header name.
956 Solaris tar general-purpose extension header.
959 POSIX pax interchange format global extensions.
962 POSIX pax interchange format per-file extensions.
973 utility is no longer a part of POSIX or the Single Unix Standard.
975 Version 2 of the Single UNIX Specification (``SUSv2'').
976 It has been supplanted in subsequent standards by
978 The ustar format is currently part of the specification for the
981 The pax interchange file format is new with
982 IEEE Std 1003.1-2001 (``POSIX.1'').
987 command appeared in Seventh Edition Unix, which was released in January, 1979.
990 program from Fourth Edition Unix which in turn replaced the
992 program from First Edition Unix.
995 public-domain implementation (circa 1987) was highly influential
996 and formed the basis of
1001 archiver is another open-source (CDDL) archiver (originally developed
1002 circa 1985) which features complete support for pax interchange
1005 This documentation was written as part of the
1010 Tim Kientzle \%<kientzle@FreeBSD.org.>