Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Tar (computing)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
{{Short description|Shell command to combine files into a single file}} {{More citations needed|date=April 2012}} {{lowercase}} {{Infobox software | name = tar | logo = | screenshot = | screenshot size = | caption = | author = [[Bell Laboratories]] | developer = Various [[open-source software|open-source]] and [[commercial software|commercial]] developers | released = {{Start date and age|1979|1}} | ver layout = stacked | latest release version = {{Multiple releases | branch1 = BSD tar | version1 = 3.7.2<ref>{{Cite web|url=https://www.libarchive.org/|title=libarchive - C library and command-line tools for reading and writing tar, cpio, zip, ISO, and other archive formats @ GitHub|website=www.libarchive.org}}</ref> | date1 = 2023-09-12 | branch2 = GNU tar | version2 = {{wikidata|property|preferred|references|edit|Q21283172|P348|P548=Q2804309}} | date2 = {{wikidata|qualifier|raw|preferred|single|Q21283172|P348|P548=Q2804309|P577}} | branch3 = pdtar | version3 = 1986-10-29<ref>{{cite newsgroup| author=John Gilmore|title=v07i088: Public-domain TAR program|date=1986-12-10|newsgroup=mod.sources|url=https://groups.google.com/g/mod.sources/c/j1tSNLD0OFk|access-date=2022-02-07|archive-url=https://web.archive.org/web/20220207070912/https://groups.google.com/g/mod.sources/c/j1tSNLD0OFk|archive-date=2022-02-07|url-status=live}}</ref><ref>{{cite web|url=http://www.decuslib.com/decus/vax87d/rcaf87/tarrdr/posixtar/|title=posixtar}}</ref> | date3 = 1986-10-29 | branch4 = Plan 9 tar | version4 = ? | date4 = ? | branch5 = star | version5 = 2023-09-28<ref>{{cite web|url=https://codeberg.org/schilytools/schilytools/releases/tag/2023-09-28|title=star|access-date=2023-11-12|archive-date=2023-11-12|archive-url=https://web.archive.org/web/20231112053301/https://codeberg.org/schilytools/schilytools/releases/tag/2023-09-28|url-status=dead}}</ref> | date5 = 2023-09-28 }} | programming language = pdtar, star, [[Plan 9 from Bell Labs|Plan 9]], [[GNU]]: [[C (programming language)|C]] | operating system = [[Unix]], [[Unix-like]], [[Plan 9 from Bell Labs|Plan 9]], [[Microsoft Windows]], [[IBM i]] | platform = [[Cross-platform]] | genre = [[Command (computing)|Command]] | license = BSD tar: [[BSD licenses|BSD-2-Clause]]<br />GNU tar: [[GNU General Public License|GPL-3.0-or-later]]<br />pdtar: [[Public domain]]<br />Plan 9: [[MIT License|MIT]]<br />star: [[Common Development and Distribution License|CDDL-1.0]] | website = }} {{Infobox file format | name = tar | icon = | extension = .tar | mime = application/x-tar | uniform type = public.tar-archive | magic = <code>u s t a r \0 0 0 </code> at byte offset 257 (for POSIX versions) <code>u s t a r \040 \040 \0 </code> (for old GNU tar format)<ref name = "GnuTarFormat">{{cite web|url=https://www.gnu.org/software/tar/manual/html_node/Standard.html|title=Basic Tar Format|last1=Gilmore|first1=John|last2=Fenlason|first2=Jay|others=and others|date=4 February 2019|website=gnu.org|publisher=[[Free Software Foundation]]|access-date=17 April 2019}}</ref> absent in pre-POSIX versions | latest release version = various | latest release date = various | open = Yes | standard = POSIX since POSIX.1, presently in the definition of ''pax''[http://pubs.opengroup.org/onlinepubs/9699919799/utilities/pax.html#tag_20_92_13_06] | genre = [[File archiver]] }} In [[computing]], '''tar''' is a [[Shell (computing)|shell]] [[command (computing)|command]] for combining multiple [[computer file]]s into a single [[archive file]]. It was originally developed for [[magnetic tape]] [[computer storage|storage]] {{endash}} reading and writing data for a sequential [[Input/output|I/O]] device with no [[file system]], and the name is short for the format description "'''t'''ape '''ar'''chive". When stored in a file system, a file that tar reads and writes is often called a ''tarball''. A tarball contains [[metadata]] for the contained files including the [[file name|name]], ownership, [[timestamp]]s, [[File-system permissions|permissions]] and [[Directory (computing)|directory]] organization. As a file containing other files with associated metadata, a tarball is useful for [[software distribution]] and [[backup]]. [[POSIX]] abandoned ''tar'' in favor of ''[[pax (command)|pax]]'', yet ''tar'' continues to have widespread use. ==History== The command was introduced to [[version 7 Unix|Unix]] in January 1979, replacing the tp program (which in turn replaced "tap").<ref name="tar5">{{cite web |url=https://www.freebsd.org/cgi/man.cgi?query=tar&apropos=0&sektion=5&manpath=FreeBSD+7.0-RELEASE&arch=default&format=html |title=tar(5) manual page |date=20 May 2004 |website=FreeBSD.org |publisher=FreeBSD |access-date=2 May 2017}}</ref> The [[file format|file structure]] was standardized in [[POSIX]].1-1988<ref>''IEEE Std 1003.1-1988, IEEE Standard for Information Technology - Portable Operating System Interface (POSIX)''</ref> and later POSIX.1-2001,<ref>IEEE Std 1003.1-2001, ''IEEE Standard for Information Technology - Portable Operating System Interface (POSIX)''</ref> and became a format supported by most modern file archiving utilities. The tar command was abandoned in POSIX.1-2001 in favor of [[pax (command)|pax]], which was to support the ustar file format, and tar was indicated for withdrawal in favor of pax at least since 1994. None-the-less, many operating systems today include tools for tar files, as well as tools to compress and decompress them, such as [[XZ Utils|xz]], [[gzip]], and [[bzip2]]. The {{Mono|tar}} command was ported to the [[IBM i]] operating system.<ref>{{cite web |title=IBM System i Version 7.2 Programming Qshell |language=en |author=IBM |website=[[IBM]] |author-link=IBM |url=https://www.ibm.com/support/knowledgecenter/ssw_ibm_i_74/rzahz/rzahzpdf.pdf?view=kc |access-date=2020-09-05 }}</ref> BSD-tar has been in [[Microsoft Windows|Windows]] since [[Windows 10 version history|2018]],<ref>{{cite web |title=Announcing Windows 10 Insider Preview Build 17063 for PC |url=https://blogs.windows.com/windowsexperience/2017/12/19/announcing-windows-10-insider-preview-build-17063-pc/ |website=Windows Experience Blog |access-date=2 July 2018 |date=2017-12-19 }}</ref><ref>{{Cite web | url=https://techcommunity.microsoft.com/t5/Containers/Tar-and-Curl-Come-to-Windows/ba-p/382409 | title=Tar and Curl Come to Windows!| date=2019-03-22}}</ref> and there are other third-party tools available for Windows. ==Rationale== Many historic tape drives read and write variable-length [[Block (data storage)|data blocks]], leaving significant wasted space on the tape between blocks (for the tape to physically start and stop moving). Some tape drives (and raw disks) support only fixed-length data blocks. Also, when writing to any medium such as a file system or network, it takes less time to write one large block than many small blocks. Therefore, the tar command writes data in records of many 512 [[Byte|B]] blocks. The user can specify a blocking factor, which is the number of blocks per record. The default is 20, producing 10 [[Kibibyte|KiB]] records.<ref>{{cite web |url=http://ftp.gnu.org/old-gnu/Manuals/tar/html_node/tar_130.html |title=Blocking |website=ftp.gnu.org |access-date=2020-08-26}}</ref> ==File format== There are multiple tar file formats, including historical and current ones. Two tar formats are codified in POSIX: [[#UStar format|ustar]] and [[#POSIX.1-2001/pax|pax]]. Not codified but still in current use is the GNU tar format. A tar archive consists of a series of file objects, hence the popular term ''tarball'', referencing how a [[Tarball (oil)|tarball]] collects objects of all kinds that stick to its surface. Each file object includes any file data, and is preceded by a 512-byte [[Header (computing)|header]] record. The file data is written unaltered except that its length is rounded up to a multiple of 512 bytes. The original tar implementation did not care about the contents of the padding bytes, and left the buffer data unaltered, but most modern tar implementations fill the extra space with zeros.<ref name = "Hoo, e7z Org., 2015" >{{ Cite web | url = http://www.e7z.org/open-tar.htm | title = Open/Extract TAR File with Freeware on Windows/Mac/Linux | access-date = 2019-09-03 | first = James | last = Hoo | website = e7z Org. | archive-url = https://web.archive.org/web/20150206035752/http://www.e7z.org/open-tar.htm | archive-date = 2015-02-06 | df = dmy-all }}</ref> The end of an archive is marked by at least two consecutive zero-filled records. (The origin of tar's record size appears to be the 512-byte disk sectors used in the Version 7 Unix file system.) The final block of an archive is padded out to full length with zeros. ===Header=== The file header record contains [[metadata]] about a file. To ensure portability across different architectures with different [[Endianness|byte orderings]], the information in the header record is encoded in [[ASCII]]. Thus if all the files in an archive are ASCII text files, and have ASCII names, then the archive is essentially an ASCII text file (containing many [[Null character|NUL characters]]). The fields defined by the original Unix tar format are listed in the table below. The link indicator/file type table includes some modern extensions. When a field is unused it is filled with NUL bytes. The header uses 257 bytes, then is padded with NUL bytes to make it fill a 512 byte record. There is no "magic number" in the header, for file identification. Pre-POSIX.1-1988 (i.e. v7) tar header: {| class="wikitable" |- ! Field offset ! Field size ! Field |- | 0 | 100 | File path and name |- | 100 | 8 | File mode (octal) |- | 108 | 8 | Owner's numeric user ID (octal) |- | 116 | 8 | Group's numeric user ID (octal) |- | 124 | 12 | File size in bytes (octal) |- | 136 | 12 | Last modification time in numeric Unix time format (octal) |- | 148 | 8 | Checksum for header record |- | 156 | 1 | Link indicator (file type) |- | 157 | 100 | Name of linked file |} The pre-POSIX.1-1988 '''Link indicator''' field can have the following values: {| class="wikitable" |+ Link indicator field |- ! Value ! Meaning |- | '0' or ([[ASCII]] [[Null character|NUL]]) | Normal file |- | '1' | [[Hard link]] |- | '2' | [[Symbolic link]] |} Some pre-POSIX.1-1988 tar implementations indicated a directory by having a trailing [[Slash (punctuation)|slash]] (/) in the name. Numeric values are encoded in [[octal]] numbers using ASCII digits, with leading zeroes. For historical reasons, a final NUL or [[Space (punctuation)|space]] character should also be used. Thus although there are 12 bytes reserved for storing the file size, only 11 octal digits can be stored. This gives a maximum file size of 8 [[gigabyte]]s on archived files. To overcome this limitation, in 2001 star introduced a base-256 coding that is indicated by setting the high-order bit of the leftmost byte of a numeric field.{{cn|date=October 2021}} GNU-tar and BSD-tar followed this idea. Additionally, versions of tar from before the first POSIX standard from 1988 pad the values with spaces instead of zeroes. The [[checksum]] is calculated by taking the sum of the unsigned byte values of the header record with the eight checksum bytes taken to be ASCII spaces (decimal value 32). It is stored as a six digit octal number with leading zeroes followed by a NUL and then a space. Various implementations do not adhere to this format. In addition, some historic tar implementations treated bytes as signed. Implementations typically calculate the checksum both ways, and treat it as good if either the signed or unsigned sum matches the included checksum. Unix filesystems support multiple links (names) for the same file. If several such files appear in a tar archive, only the first one is archived as a normal file; the rest are archived as hard links, with the "name of linked file" field set to the first one's name. On extraction, such hard links should be recreated in the file system. ===UStar format=== Most modern tar programs read and write archives in the UStar (''Unix Standard TAR''<ref name="tar5"/><ref>{{cite book |last=Kientzle |first=Tim |date=1995 |title=Internet File Formats |publisher=Coriolis Groups Books |isbn=978-1-883577-56-8 |url=https://archive.org/details/mac_Internet_File_Formats_1995 |page=[https://archive.org/details/mac_Internet_File_Formats_1995/page/n202 196] |access-date=2022-11-10}}</ref>) format, introduced by the POSIX IEEE P1003.1 standard from 1988. It introduced additional header fields. Older tar programs will ignore the extra information (possibly extracting partially named files), while newer programs will test for the presence of the "ustar" string to determine if the new format is in use. The UStar format allows for longer file names and stores additional information about each file. The maximum filename size is 255, but it is split among a preceding path "filename prefix" and the filename itself, so can be much less.<ref name="gnu.org">{{Cite web | url=https://www.gnu.org/software/tar/manual/html_chapter/Formats.html#Compression|title = GNU tar 1.32: 8.1 Using Less Space through Compression | date = 2019-02-23 | website = GNU | access-date = 2019-08-11}}</ref> {| class="wikitable" |- ! Field offset ! Field size ! Field |- | 0 | 156 | ''(Several fields, same as in the old format)'' |- | 156 | 1 | Type flag |- | 157 | 100 | ''(Same field as in the old format)'' |- | 257 | 6 | UStar indicator, "ustar", then NUL |- | 263 | 2 | UStar version, "00" |- | 265 | 32 | Owner user name |- | 297 | 32 | Owner group name |- | 329 | 8 | Device major number |- | 337 | 8 | Device minor number |- | 345 | 155 | Filename prefix |} The ''type flag'' field can have the following values: {| class="wikitable" |+ Type flag field |- ! Value ! Meaning |- | '0' or ([[ASCII]] [[Null character|NUL]]) | Normal file |- | '1' | [[Hard link]] |- | '2' | [[Symbolic link]] |- | '3' | [[Device file|Character special]] |- | '4' | [[Device file|Block special]] |- | '5' | [[Directory (computing)|Directory]] |- | '6' | [[Named pipe|FIFO]] |- | '7' | Contiguous file |- | 'g' | Global extended header with meta data (POSIX.1-2001) |- | 'x' | Extended header with metadata for the next file in the archive (POSIX.1-2001) |- | 'A'–'Z' | Vendor specific extensions (POSIX.1-1988) |- | All other values | Reserved for future standardization |} POSIX.1-1988 vendor specific extensions using link flag values 'A'–'Z' partially have a different meaning with different vendors and thus are seen as outdated and replaced by the POSIX.1-2001 extensions that also include a vendor tag. Type '7' (Contiguous file) is formally marked as reserved in the POSIX standard, but was meant to indicate files which ought to be contiguously allocated on disk. Few operating systems support creating such files explicitly, and hence most TAR programs do not support them, and will treat type 7 files as if they were type 0 (regular). An exception is older versions of GNU tar, when running on the [[MASSCOMP]] RTU (Real Time Unix) operating system, which supported an O_CTG flag to the open() function to request a contiguous file; however, that support was removed from GNU tar version 1.24 onwards. ===POSIX.1-2001/pax=== In 1997, [[Sun Microsystems|Sun]] proposed a method for adding extensions to the tar format. This method was later accepted for the POSIX.1-2001 standard. This format is known as ''extended tar'' format or [[pax (command)|pax]] format. The new tar format allows users to add any type of vendor-tagged vendor-specific enhancements. The following tags are defined by the POSIX standard: * '''atime''', '''mtime''': all timestamps of a file in arbitrary resolution (most implementations use nanosecond granularity) * '''path''': path names of unlimited length and character set coding * '''linkpath''': symlink target names of unlimited length and character set coding * '''uname''', '''gname''': user and group names of unlimited length and character set coding * '''size''': files with unlimited size (the historic tar format is 8 GB) * '''uid''', '''gid''': userid and groupid without size limitation (the historic tar format is limited to a max. id of 2097151) * a character set definition for path names and user/group names ([[UTF-8]]) In 2001, the Star program became the first tar to support the new format.{{cn|date=October 2021}} In 2004, GNU tar supported the new format,<ref>[https://git.savannah.gnu.org/cgit/tar.git/tree/NEWS NEWS], git.savannah.gnu.org - search for "Added support for POSIX.1-2001 and ustar archive formats."</ref> though it does not write it as its default output from the tar program yet.<ref name="gnu.org2">{{Cite web | url=https://www.gnu.org/software/tar/manual/html_section/Formats.html |title = GNU tar 1.34: 8. Controlling the Archive Format | website = GNU | access-date = 2022-07-11}}</ref> The pax format is designed so that all implementations able to read the UStar format will be able to read the pax format as well. The only exceptions are files that make use of extended features, such as longer file names. For compatibility, these are encoded in the tar files as special {{code|x}} or {{code|g}} type files, typically under a {{code|PaxHeaders.XXXX}} directory.<ref>{{man|1|pax|SUS}}</ref>{{rp|exthdr.name}} A pax-supporting implementation would make use of the information, while non-supporting ones like [[7-Zip]] would process them as additional files.<ref>{{cite web |title=#2116 Tars with pax headers not parsed |url=https://sourceforge.net/p/sevenzip/bugs/2116/ |website=7-Zip / Bugs {{!}} SourceForge}}</ref> == Features of the archival utilities == Besides creating and extracting archives, the functionality of the various archival utilities varies. For example, implementations might automatically detect the format of compressed TAR archives for extraction so the user does not have to specify it, and let the user limit adding files to those modified after a specified date.<ref>[https://www.gnu.org/software/tar/manual/html_section/after.html GNU tar 1.35: 6.8 Operating Only on New Files]</ref><ref>[https://www.baeldung.com/linux/bsd-tar-gnu-tar-star Differences Between BSD tar and GNU tar and star {{pipe}} Baeldung on Linux]</ref> ==Uses== === Command syntax === tar [-options] <name of the tar archive> [files or directories which to add into archive] Basic options: * <code>-c, --create</code> — create a new archive; * <code>-a, --auto-compress</code> — additionally compress the archive with a compressor which will be automatically determined by the file name extension of the archive. If the archive's name ends with {{code|*.tar.gz}} then use [[gzip]], if {{code|*.tar.xz}} then use [[XZ Utils|xz]], {{code|*.tar.zst}} for [[Zstandard]] etc.; * <code>-r, --append</code> — append files to the end of an archive; * <code>-x, --extract, --get</code> — extract files from an archive; * <code>-f, --file</code> — specify the archive's name; * <code>-t, --list</code> — show a list of files and folders in the archive; * <code>-v, --verbose</code> — show a list of processed files. === Basic usage === Create an archive file {{code|archive.tar}} from the file {{code|README.txt}} and directory {{code|src}}: <syntaxhighlight lang="console"> $ tar -cvf archive.tar README.txt src </syntaxhighlight> Extract contents for the {{code|archive.tar}} into the current directory: <syntaxhighlight lang="console"> $ tar -xvf archive.tar </syntaxhighlight> Create an archive file {{code|archive.tar.gz}} from the file {{code|README.txt}} and directory {{code|src}} and compress it with [[gzip]] : <syntaxhighlight lang="console"> $ tar -cavf archive.tar.gz README.txt src </syntaxhighlight> Extract contents for the {{code|archive.tar.gz}} into the current directory: <syntaxhighlight lang="console"> $ tar -xvf archive.tar.gz </syntaxhighlight> ===Tarpipe=== A tarpipe is the method of writing an archive to [[Standard streams#Standard output (stdout)|standard output]] and piping it to another tar process on its [[Standard streams#Standard input (stdin)|standard input]], working in another directory, where it is unpacked. This process copies an entire source directory tree including all special files, for example: <syntaxhighlight lang="console"> $ tar cf - srcdir | tar x -C destdir </syntaxhighlight> ===Software distribution=== The tar format continues to be used extensively for [[Open source|open-source]] [[software distribution]]. *NIX-distributions use it in various source- and binary-package distribution mechanisms, with most software [[source code]] made available in compressed tar archives.{{Citation needed|date=July 2020}} ==Limitations== The original tar format was created in the early days of Unix, and despite current widespread use, many of its design features are considered dated.<ref>{{Cite web|url=http://duplicity.nongnu.org/new_format.html|title=duplicity: New file format|website=duplicity.nongnu.org}}</ref> Other formats have been created to address the shortcomings of tar. === File names === Due to the [[Tar_(computing)#Header|field size]], the original TAR format was unable to store file paths and names in excess of 100 characters. To overcome this problem while maintaining [[backwards compatibility|readability by existing TAR utilities]], GNU tar stores file paths and names in excess of the 100 characters are stored in <code>@LongLink</code> entries that would be seen as ordinary files by TAR utilities unaware of this feature.<ref>[https://github.com/gitGNU/gnu_tar/blob/master/src/create.c#L546 gnu_tar/src/create.c at master · gitGNU/gnu_tar · GitHub], line 546</ref> Similarly, the [[Tar (computing)#POSIX.1-2001/pax|PAX]] format uses <code>PaxHeaders</code> entries.<ref>[https://github.com/openbsd/src/blob/8df76133309eacd4092b091ee0504adb842322a5/bin/pax/tar.c#L1066 src/bin/pax/tar.c at 8df76133309eacd4092b091ee0504adb842322a5 · openbsd/src · GitHub], line 1066</ref> === Attributes === Many older tar implementations do not record nor restore extended attributes (xattrs) or [[access-control list]]s (ACLs). In 2001, Star introduced support for ACLs and extended attributes, through its own tags for POSIX.1-2001 pax. bsdtar uses the star extensions to support ACLs.<ref name=bsd>{{Man|5|tar|FreeBSD}}</ref> More recent versions of GNU tar support Linux extended attributes, reimplementing star extensions.<ref name = "Les bons comptes, 2014">{{ Cite web | url = http://www.lesbonscomptes.com/pages/extattrs.html | title = Extended attributes: the good, the not so good, the bad. | access-date = 2019-09-03 | date = 2014-07-15 | website = Les bons comptes | quote = The extended attributes can be very valuable for storing file metadata (e.g. <nowiki>author="John Smith"</nowiki>, <nowiki>subject="country landscape"</nowiki>), in the many cases where you do not want or can't store this data in the file internal properties. | archive-url = https://web.archive.org/web/20141214001530/http://www.lesbonscomptes.com/pages/extattrs.html |archive-date=2014-12-14| df = dmy-all }}</ref> A number of extensions are reviewed in the filetype manual for BSD tar, tar(5).<ref name=bsd/> ===Tarbomb=== {{redirect-distinguish|Tarbomb|zip bomb}} A '''tarbomb''', in [[Jargon File|hacker slang]], is a tarball containing a large number of items whose contents are written to the current directory or some other existing directory when untarred instead of the directory created by the tarball specifically for the extracted outputs. <ref>{{cite web |title=Tarbomb Definition |language=en |website=[[The Linux Info Project]] |url=https://www.linfo.org/tarbomb.html |access-date=2024-12-12 }}</ref> It is at best an inconvenience to the user, who is obliged to identify and delete a number of files interspersed with the directory's other contents. Such behavior is considered bad etiquette on the part of the archive's creator. A related problem is the use of [[Path (computing)|absolute path]]s or [[Directory (computing)|parent directory]] references when creating tar files. Files extracted from such archives will often be created in unusual locations outside the working directory and, like a tarbomb, have the potential to overwrite existing files. However, modern versions of FreeBSD and GNU tar do not create or extract absolute paths and parent-directory references by default, unless it is explicitly allowed with the flag {{code|-P}} or the option {{code|--absolute-names}}. The bsdtar program, which is also available on many operating systems and is the default tar implementation on [[macOS|Mac OS X]] v10.6, also does not follow parent-directory references or symbolic links.<ref>{{Cite web|url=https://man.freebsd.org/cgi/man.cgi?query=bsdtar&sektion=1&format=html|title=bsdtar(1)|website=man.freebsd.org}}</ref> <!-- https://developer.apple.com/mac/library/documentation/Darwin/Reference/ManPages/man1/bsdtar.1.html Man page for "bsdtar", as provided by Apple. -->{{failed verification|date=July 2022}} If a user has only a very old tar available, which does not feature those security measures, these problems can be mitigated by first examining a tar file using the command <code>tar tf archive.tar</code>, which lists the contents and allows to exclude problematic files afterwards. These commands do not extract any files, but display the names of all files in the archive. If any are problematic, the user can create a new empty directory and extract the archive into it—or avoid the tar file entirely. Most graphical tools can display the contents of the archive before extracting them. [[Vim (text editor)|Vim]] can open tar archives and display their contents. [[GNU Emacs]] is also able to open a tar archive and display its contents in a [[dired]] buffer. ===Random access=== The tar format was designed without a centralized index or table of content for files and their properties for streaming to tape backup devices. Instead, the metadata for each file (such as name, size, time stamps) for each file is stored in a header before each file. The archive must be read sequentially to list or extract files. For large tar archives, this causes a performance penalty, making tar archives unsuitable for situations that often require random access to individual files. In turn, this design makes TAR archives resilient against damage from missing portions, in both the form of digital files and physical tape.{{cn|date=February 2025}} A truncated TAR file with missing parts on either ends still allows recovering the parts that are not missing, including the file paths and file names and metadata, by starting from the first TAR header that is not missing.<ref>Creating TAR with 100 KB missing at the beginning: <code>tail --bytes=+100000 "intact archive.tar" >>"missing beginning.tar"</code>. Next header can be found using a [[hex editor]]. Recover using <code>dd if="missing beginning.tar" of=recovered.tar ibs=''[bytes until next header which starts with file path and name]'' skip=1</code>. Quotation marks are not needed for file names without spaces.</ref> With a well-formed tar file stored on a seekable (i.e. allows efficient random reads) medium, the {{code|tar}} program can still relatively quickly (in linear time relative to file count) look for a file by skipping file reads according to the "size" field in the file headers. This is the basis for option {{code|-n}} in GNU tar. When a tar file is compressed whole, the compression format, being usually non-seekable, prevents this optimization from being done.<ref>{{cite web |last1=BillThor |title=What makes a tar archive seekable? |url=https://superuser.com/a/1235409 |website=Super User |access-date=15 December 2023 |language=en |date=July 28, 2017}}</ref> To maintain seekability, tar files must be also concatenated properly, by removing the trailing zero block at the end of each file.<ref>{{cite web |title=GNU tar 1.35: 4.2.4 Combining Archives with --concatenate |url=https://www.gnu.org/software/tar/manual/html_node/concatenate.html |website=www.gnu.org}}</ref> ===Duplicates=== Another issue with tar format is that it allows several (possibly different) files in archive to have identical paths and filenames. When extracting such archive, usually the latter version of a file overwrites the former. This can create a non-explicit (unobvious) tarbomb, which technically does not contain files with absolute paths or referring to parent directories, but still causes overwriting files outside current directory (for example, archive may contain two files with the same path and filename, first of which is a [[symbolic link|symlink]] to some location outside current directory, and second of which is a regular file; then extracting such archive on some tar implementations may cause writing to the location pointed to by the symlink). ==Key implementations== <!-- Implementations included with major unixoid OS only. No general archivers that can just "also" do tar - they probably just include libarchive included here. --> Historically, many systems have implemented tar, and many [[Comparison of file archivers|general file archivers]] have at least partial support for tar (often using one of the implementations below). The history of tar is a story of incompatibilities, known as the "tar wars". Most tar implementations can also read and create [[cpio]] and [[pax (command)|pax]] (the latter actually is a ''tar''-format with [[POSIX]]-2001-extensions). Key implementations in order of origin: * '''[[Solaris (operating system)|Solaris]] tar''', based on the original Unix V7 tar <!-- is this correct? --> and comes as the default on the Solaris operating system * '''[[GNU]] tar''' is the default on most [[Linux]] distributions. It is based on the public domain implementation pdtar which started in 1987. Recent versions can use various formats, including ustar, pax, GNU and v7 formats. * '''[[FreeBSD]] tar''' (also '''BSD tar''') has become the default tar on most [[Berkeley Software Distribution]]-based operating systems including [[macOS|Mac OS X]]. The core functionality is available as [[libarchive]] for inclusion in other applications. This implementation automatically detects the format of the file and can extract from tar, pax, cpio, zip, rar, ar, xar, rpm and ISO 9660 cdrom images. It also comes with a functionally equivalent cpio command-line interface. * '''Schily tar''', better known as '''star''' ({{IPAc-en|ˈ|ɛ|s|ˌ|t|ɑːr}}, {{respell|ESS|tar}}),<ref>{{ Cite web | url = https://cdrtools.sourceforge.net/private/star.html | title = Star a very fast and Posix 1003.1 compliant tar archiver for UNIX | access-date = 2023-09-02 | first = Jörg | last = Schilling | archive-url = https://web.archive.org/web/20230709001233/https://cdrtools.sourceforge.net/private/star.html | archive-date = 2023-07-09 }}</ref> is historically significant as some of its extensions were quite popular. First published in April 1997,<ref>{{cite web|url=https://invisible-island.net/autoconf/portability-tar.html#var_star |title=TAR versus Portability: Schily tar |date=January 4, 2015 |access-date=October 23, 2021 |author=Thomas E. Dickey}}</ref> its developer has stated that he began development in 1982.<ref>{{cite web |url=http://schilytools.sourceforge.net/man/man1/star.1.html |title=star - unique standard tape archiver |author=Jörg Schilling |date=September 4, 2021 |access-date=October 23, 2021 }}{{Dead link|date=March 2025 |bot=InternetArchiveBot |fix-attempted=yes }}</ref> * '''Python tarfile''' module supports multiple tar formats, including ustar, pax and gnu; it can read but not create V7 format and the SunOS tar extended format; pax is the default format for creation of archives.<ref>[https://docs.python.org/3/library/tarfile.html tarfile] module, python.org</ref> Available since 2003.<ref>[https://github.com/python/cpython/blob/3.10/Lib/tarfile.py tarfile.py], github.com</ref> Additionally, most [[Pax (command)|pax]] and [[cpio]] implementations can read and create multiple types of tar files. ==Suffixes for compressed files== ''tar'' archive files usually have the file suffix ''.tar'' (e.g. ''somefile.tar''). A tar archive file contains uncompressed byte streams of the files which it contains. To achieve archive compression, a variety of [[data compression|compression]] programs are available, such as [[gzip]], [[bzip2]], [[XZ Utils|xz]], [[lzip]], [[Lempel–Ziv–Markov chain algorithm|lzma]], [[zstd]], or [[compress]], which compress the entire tar archive. Typically, the compressed form of the archive receives a filename by appending the format-specific compressor suffix to the archive file name. For example, a tar archive ''archive.tar'', is named ''archive.tar.gz'', when it is compressed by gzip. Popular tar programs like the [[Berkeley Software Distribution|BSD]] and [[GNU]] versions of tar support the [[Command-line interface|command-line options]] ''Z'' (compress), ''z'' (gzip), and ''j'' (bzip2) to compress or decompress the archive file upon creation or unpacking. Relatively recent additions include ''--lzma'' ([[Lempel–Ziv–Markov chain algorithm|LZMA]]), ''--lzop'' ([[lzop]]), ''--xz'' or ''J'' ([[XZ Utils|xz]]), ''--lzip'' (lzip), and ''--zstd''.<ref>{{cite web | url = https://lists.gnu.org/archive/html/info-gnu/2019-01/msg00001.html | title = tar-1.31 released [stable] | last = Poznyakoff | first = Sergey | date = 2019-01-02 | website = GNU mailing lists | access-date = 2019-08-06}}</ref> The decompression of these formats is handled automatically if supported filename extensions are used, and compression is handled automatically using the same filename extensions if the option ''--auto-compress'' (short form ''-a'') is passed to an applicable version of GNU tar.<ref name="gnu.org"/> BSD tar detects an even wider range of compressors ([[lrzip]], [[LZ4 (compression algorithm)|lz4]]), using not the filename but the data within.<ref>{{man|1|tar|FreeBSD}}</ref> Unrecognized formats are to be manually compressed or decompressed by piping. [[MS-DOS]]'s [[8.3 filename]] limitations resulted in additional conventions for naming compressed tar archives. However, this practice has declined with [[File Allocation Table|FAT]] now offering [[long filename]]s. [[File:Targzip.svg|thumb|upright=1.2|Tar archiving is often used together with a compression method, such as [[gzip]], to create a compressed archive. As shown, the combination of the files in the archive is compressed as one unit.]] {| class="wikitable" |+ File suffix equivalents<ref name="gnu.org"/> !Compressor ! Long !! Short |- |[[bzip2]] | .tar.bz2 || .tb2, .tbz, .tbz2, .tz2 |- |[[gzip]] | .tar.gz || .taz, .tgz |- |[[lzip]] | .tar.lz || |- |[[Lempel–Ziv–Markov chain algorithm|lzma]] | .tar.lzma || .tlz |- |[[lzop]] | .tar.lzo || |- |[[XZ Utils|xz]] | .tar.xz || .txz |- |[[compress]] | .tar.Z || .tZ, .taZ |- |[[Zstandard|zstd]] | .tar.zst || .tzst |} ==See also== * [[Comparison of archive formats]] * [[Comparison of file archivers]] * [[List of archive formats]] * [[List of POSIX commands]] ==References== {{Reflist|colwidth=30em}} ==External links== {{Wikibooks|Guide to Unix|Commands/File Compression#tar}} {{Wikibooks|Windows Batch Scripting}} * [https://pubs.opengroup.org/onlinepubs/009656399/toc.pdf X/Open CAE Specification Commands and Utilities Issue 4, Version 2] (pdf), 1994, opengroup.org – indicates tar as to be withdrawn * [https://pubs.opengroup.org/onlinepubs/007908799/xcu/tar.html tar] in The Single UNIX Specification, Version 2, 1997, opengroup.org – indicates applications should migrate to pax * [https://pubs.opengroup.org/onlinepubs/009695399/xrat/xcu_chap04.html C.4 Utilities] in The Open Group Base Specifications Issue 6, 2004 Edition, opengroup.org – indicates tar as removed * {{man|1|pax|SUS}} – specifies the ustar and pax file formats * {{man|1|tar|v7}} * {{man/format|1|tar|https://www.gnu.org/software/tar/manual/}} – manual from [[GNU]] * {{man|1|tar|Plan 9}} * {{man|1|tar|Solaris}} * {{man|1|tar|FreeBSD}} * {{man|1|tar|OpenBSD}} * {{man|1|tar|Linux}} * {{man|5|tar|FreeBSD}} * [https://ss64.com/nt/tar.html TAR - Windows CMD - SS64.com] {{Archive formats}} {{Compression software}} {{Windows commands}} {{DEFAULTSORT:Tar (File Format)}} [[Category:Archive formats]] [[Category:Free backup software]] [[Category:GNU Project software]] [[Category:Unix archivers and compression-related utilities]] [[Category:Plan 9 commands]] [[Category:IBM i Qshell commands]]
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)
Pages transcluded onto the current version of this page
(
help
)
:
Template:Archive formats
(
edit
)
Template:Citation needed
(
edit
)
Template:Cite book
(
edit
)
Template:Cite web
(
edit
)
Template:Cn
(
edit
)
Template:Code
(
edit
)
Template:Compression software
(
edit
)
Template:Dead link
(
edit
)
Template:Endash
(
edit
)
Template:Failed verification
(
edit
)
Template:IPAc-en
(
edit
)
Template:Infobox
(
edit
)
Template:Infobox file format
(
edit
)
Template:Infobox software
(
edit
)
Template:Lowercase
(
edit
)
Template:Main other
(
edit
)
Template:Man
(
edit
)
Template:Man/format
(
edit
)
Template:Mono
(
edit
)
Template:More citations needed
(
edit
)
Template:Pipe
(
edit
)
Template:Redirect-distinguish
(
edit
)
Template:Reflist
(
edit
)
Template:Respell
(
edit
)
Template:Rp
(
edit
)
Template:Short description
(
edit
)
Template:Sister project
(
edit
)
Template:Template other
(
edit
)
Template:Wikibooks
(
edit
)
Template:Windows commands
(
edit
)