The basics
What is a TAR file?
A TAR file is many files and folders glued into one, with a short header before each file saying its name, size, permissions, owner and date. That's all it does: it doesn't compress anything. A folder of 10 MB becomes a TAR file of slightly more than 10 MB.
The name means tape archive. tar was written in 1979 to copy files to magnetic tape, which can only be read and written from start to end. That's why the format has no table of contents and just writes one file after another. It suits anything that works as a stream: piping between programs, backups, and network copies such as tar -cf - folder | ssh server tar -xf -.
Compression is a separate step on top. A `.tar.gz` or `.tgz` is a TAR file compressed with gzip; .tar.bz2 uses bzip2 and .tar.xz uses XZ. Splitting the jobs like this is the Unix habit of one tool per task, and it lets the compressor see all the files as one stream.
Plain, uncompressed .tar files are less common to download, but you meet them in container images saved with docker save, in backup systems, and whenever the data is already compressed (photos, videos) so compressing again would gain nothing.
Anatomy
What's inside a TAR file
A tar file is a row of 512-byte blocks. Each file gets one header block, then its data, padded with zeros to a whole number of blocks. Here is sample-project.tar with the real bytes, and the header of README.md field by field. Numbers in a tar header are written as ASCII octal digits.
offset bytes part
0 73 61 6D 70 6C 65 2D 70 72 6F 6A … header: "sample-project/", type 5
512 73 61 6D 70 6C 65 2D 70 72 6F 6A … header: "sample-project/README.md"
+100 30 30 30 30 36 34 34 00 mode "0000644"
+108 30 30 30 31 37 35 30 00 uid "0001750" = 1000
+116 30 30 30 30 31 34 34 00 gid "0000144" = 100
+124 30 30 30 30 30 30 30 31 33 31 30 00 size "00000001310" = 712
+136 31 35 32 37 30 31 31 31 31 30 30 00 mtime "15270111100"
+148 30 31 33 37 34 35 00 20 checksum "013745"
+156 30 typeflag "0" = regular file
+157 00 00 00 … linkname: empty
+257 75 73 74 61 72 00 30 30 magic "ustar", version "00"
+265 61 64 61 00 … uname "ada"
+297 75 73 65 72 73 00 … gname "users"
+345 00 00 00 … prefix: empty, zeros to 512
1024 23 20 53 61 6D 70 6C 65 20 70 72 … README.md: "# Sample pr…"
1736 00 00 00 … zero padding to 2,048
2048 header: CHANGELOG.txt, data at 2,560
3072 header: data/ (type 5)
3584 header: data/readings.csv, 9,265 bytes
13824 header: data/stations.json
15360 header: images/ and images/logo.png
17408 header: scripts/ and scripts/summary.sh
18944 00 × 1,024 two zero blocks: end of archive
19968 00 × 512 padding to 20,480 bytes- 1
name (offset +0, 100 bytes)The path
The full path inside the archive,
sample-project/README.md, padded with zero bytes. Folders are entries too, with names ending in/. 100 bytes is the limit in this field; ustar can add 155 more in the prefix field. - 2
"0000644"Permissions
Unix mode bits in octal: 644 is
rw-r--r--.scripts/summary.shhas 755, so it stays executable after extraction on Linux and macOS. - 3
"0001750" · "0000144"Owner and group IDs
1000 and 100 in octal. When
rootextracts an archive, tar restores these numbers; a normal user becomes the owner of everything extracted. - 4
"00000001310"Size
712 bytes, as 11 octal digits. That's where the classic 8 GiB limit per file comes from; GNU and pax archives get round it.
- 5
"15270111100"Modification time
Unix seconds in octal: 1793102400, which is 27 October 2026, 12:00:00 UTC. Whole seconds only, unless a pax header adds fractions.
- 6
"013745" 00 20Header checksum
The sum of all 512 header bytes, counting the checksum field itself as spaces. It's the only integrity check in tar: the file data has none.
- 7
"0"Type flag
0regular file,1hard link,2symbolic link,5directory,3/4devices,6FIFO. Extensions addxandg(pax headers) andLandK(GNU long names). - 8
"ustar" 00 "00"Magic and version
Marks a POSIX ustar or pax header. GNU format writes
ustarfollowed by two spaces and a zero byte instead. File type detectors look for this at offset 257. - 9
"ada" · "users"Owner and group names
Names as well as numbers, so an archive can be restored on a system where user
adahas a different ID. - 10
00 × 1,024End of archive
Two blocks of zeros. Tools then pad to a whole record, by default 20 blocks (10,240 bytes), a habit from tape drives. That's why tiny archives are 10 KB.
Under the hood
How a TAR file works: headers, blocks and no index
- Everything is in 512-byte blocks. A header is one block. File data fills as many blocks as needed, padded with zeros. So the archive's size is always a multiple of 512.
- Headers are text. Numbers are written as octal digits in ASCII, which made the format readable on any machine in 1979 and still makes it easy to inspect in a hex viewer.
- There's no index. To list a TAR file, a tool reads the first header, skips over the data, reads the next header, and so on to the end. Uncompressed, that skip is fast; inside a
.tar.gzit means decompressing everything. - The end is two zero blocks, followed by padding to a whole record (10,240 bytes by default in GNU tar, bsdtar and Python).
- Appending is easy.
tar -rf archive.tar newfilewrites over the end marker and adds a new one. If a name appears twice, the later copy wins on extraction.
tar plus a compressor
Because tar produces one continuous stream, a compressor that runs over it can find repeats across file boundaries, which ZIP's file-by-file compression can't. The .tar.gz page compares the two with real numbers.
Versions
Versions of the format: v7, ustar, pax and GNU
The 512-byte header has been extended several times. Most tools read all the variants; what they write differs.
| Format | From | Limits and features |
|---|---|---|
| v7 | Seventh Edition Unix, 1979 | Names up to 100 bytes, no owner names, no magic number. Only of historical interest. |
| ustar | POSIX.1-1988 | Adds the ustar magic, owner and group names, device files and a 155-byte prefix, so paths can reach 255 bytes. Files up to 8 GiB; link targets still 100 bytes. |
| GNU | GNU tar | Long names and link targets in separate ././@LongLink entries, larger numbers in binary, sparse files, multi-volume and incremental backups. GNU tar writes it by default. |
| pax | POSIX.1-2001 | Adds extended headers of key=value text before an entry (type x) or for the whole archive (type g): unlimited path length and file size, UTF-8 names, sub-second times, extended attributes. Python's tarfile writes it by default. |
The extensions are designed to degrade gracefully. An old ustar reader that meets a pax archive extracts the extended headers as small text files called something like PaxHeaders.1234/name, and an old reader of GNU archives creates a file called ././@LongLink. The real files still come out, with shortened names.
Metadata
What tar keeps that ZIP often loses
tar was built to back up Unix systems, so it records what a Unix file system needs to put a file back exactly:
- Permissions, including the execute bit that makes scripts and programs runnable.
- Owner and group, as numbers and names. A normal user extracting an archive becomes the owner of everything;
rootgets the original owners back. - Symbolic links as links, not as copies of the file they point to.
- Hard links: a second name for the same file is stored once, with a link entry for the other name.
- Device files, FIFOs and empty folders.
- Extended attributes and ACLs, in pax headers, if you ask for them (
--xattrs,--aclsin GNU tar).
That's why Linux software, source code and server backups travel as compressed tar files. On Windows most of this metadata has nowhere to go: permissions and owners are ignored, and creating symbolic links needs Developer Mode or administrator rights.
Troubleshooting
Common tar problems and messages
This does not look like a tar archive: the file isn't tar at all (a ZIP, an HTML error page) or it's compressed in a way tar didn't detect. Runfile archive.tarto see what it is.Removing leading '/' from member names: the archive was made with absolute paths. GNU tar strips the/and extracts relative to the current folder, which is what you want. It's a warning, not an error.Ignoring unknown extended header keyword: an archive made on macOS or with another tool contains pax keys GNU tar doesn't know, such asLIBARCHIVE.xattrentries. The files are fine.._files everywhere: macOS'starstores Finder metadata as extra._namefiles. Create the archive withCOPYFILE_DISABLE=1 tar -cf …to leave them out.- A tiny archive is 10 KB: the end marker and padding to a 10,240-byte record.
sample-gnu.tarholds about 430 bytes of text and is 10,240 bytes. - Files land all over the current folder: the archive has no top-level folder (a "tarbomb"). List it first with
tar -tf, and extract into a new folder withtar -xf archive.tar -C newfolder. - Names that are invalid on Windows, such as ones containing
:or?, or two names that differ only in upper and lower case, fail or overwrite each other when extracted on Windows.
Security
Is it safe to extract a TAR file? Paths, links and permissions
Listing a tar file (tar -tvf) is safe. Extracting one from an untrusted source is the risky part, because a header can say almost anything:
- Path traversal. An entry named with
../components can climb out of the folder you extract to and overwrite a file elsewhere, such as a shell startup script. - Absolute paths. An entry named
/etc/somethingwould be written to that exact place if the tool honoured it. - Symbolic link tricks. An archive can contain a link
dirpointing to/home/user/.ssh, followed by a filedir/authorized_keys. A naive extractor creates the link, then writes the file through it, outside the target folder. Hard links can point outside in the same way. - Permissions and ownership. Extracted as
root, an archive can create setuid programs, device files, or files owned by other users. - Tarbombs and size. An archive can scatter thousands of files in the current folder, and a compressed one can expand enormously (see gzip bombs).
GNU tar and bsdtar refuse .. paths, strip leading slashes, and handle links with care unless told otherwise (-P or --absolute-names turns that off). Libraries are another matter. Python's tarfile followed .. paths by default for years (CVE-2007-4559); Python 3.12 added extraction filters, and Python 3.14 made the safe data filter the default.
If you write code that extracts tar files
Use a safe mode where one exists (filter="data" in Python). Otherwise resolve each entry's destination and refuse it unless it's inside the target folder, refuse absolute paths, links that point outside and device files, don't restore owners or setuid bits, extract into a new empty folder, and cap the total size and number of files.
How to
How to open and create a TAR file
| Task | Command |
|---|---|
| List the contents | tar -tvf archive.tar |
| Extract here | tar -xf archive.tar |
| Extract into a folder | tar -xf archive.tar -C target/ |
| Extract one file | tar -xf archive.tar sample-project/README.md |
| Create from a folder | tar -cf archive.tar folder/ |
| Create in POSIX pax format | tar --format=pax -cf archive.tar folder/ |
- Linux: GNU tar is installed everywhere; file managers open
.tarfiles too. - macOS: double-click to extract with Archive Utility, or use
tarin Terminal (it's bsdtar, from the libarchive project, with the same basic options). - Windows: Windows 10 (from version 1803) and 11 include
tar.exe, also bsdtar, so the commands above work in Command Prompt and PowerShell. Recent Windows 11 versions also open and create tar archives in File Explorer. 7-Zip opens them on any version. - Programming: Python's
tarfile, Go'sarchive/tar, Node packages such astar, and libarchive for C.
Free downloads
Sample TAR files to download
Free sample tar files covering the three formats you'll meet: POSIX ustar, POSIX pax and GNU. Each one lists cleanly with GNU tar (tar -tvf) and Python's tarfile. Every entry is dated 27 October 2026, 12:00 UTC, and owned by the fictional user ada (uid 1000, group users, gid 100).
Browsers can't show this kind of file in a page. Download it to open it in the app it belongs to.
What's inside sample-project.tar
A small made-up project folder in plain POSIX ustar format, the most widely readable variant. The anatomy above shows its layout byte by byte.
Folder entries
sample-project/and its three subfolders are entries of type5, so empty folders would survive too.Text and data
A Markdown README, a changelog, a 240-row CSV of fictional weather readings and a JSON file describing the stations.
A PNG
images/logo.png, a 160 × 96 image drawn for these samples. tar stores it as is, with no compression.An executable script
scripts/summary.shhas mode 755. Extract it on Linux or macOS and checkls -lshowsrwxr-xr-x.Owner names and numbers
Each header holds
ada/usersand 1000/100.tar -tvfshows the names,tar --numeric-owner -tvfthe numbers.The end
Content ends at 18,944 bytes. Then come two zero blocks and padding to 20,480 bytes, two 10,240-byte records.
All sample TAR files
POSIX ustar archive with folders
sample-project.tar · 20 KB (20,480 bytes)
10 entries in plain ustar format: four folders, text, CSV, JSON, a PNG and an executable shell script.
- Testing extraction, listing and permissions
- Learning the header layout in a hex viewer
POSIX pax archive with a long UTF-8 name
sample-pax-utf8.tar · 10 KB (10,240 bytes)
Starts with a global header (type
g) holding a comment. Then a file with a 158-byte German and Japanese path and an owner namedzoë, neither of which fits a ustar header, each carried in an extended header (typex).- Checking UTF-8 file names survive extraction
- Testing pax header support in libraries
GNU format with links and a long name
sample-gnu.tar · 10 KB (10,240 bytes)
Made with GNU tar 1.35 and
--format=gnu: a 126-byte path stored in a././@LongLinkentry, a relative symbolic link (latest.txt→releases/v2.txt) and a hard link, both pointing inside the archive.- Testing GNU long-name support
- Checking how a tool restores symbolic and hard links
100 KB TAR file
sample-100kb.tar · 100 KB (102,400 bytes)
Exactly 102,400 bytes: 200 blocks of 512, or ten 10,240-byte records. Holds a README and a 99 KB CSV.
- Upload and size-limit tests
- Compressor benchmarks
Ways to test with them
- Permissions: extract
sample-project.taron Linux or macOS;sample-project/scripts/summary.shshould be executable and run when called by its path. - UTF-8 names: the long name in
sample-pax-utf8.tarshould come out as German and Japanese text. Question marks, octal escapes like\303\234or aPaxHeadersfolder mean the tool ignored the pax header. - Links: after extracting
sample-gnu.tar,latest.txtshould be a symbolic link andsame-as-v1.txta second name forreleases/v1.txt. Tools that can't make links copy the files or skip them. - Upload limits:
sample-100kb.taris exactly 102,400 bytes, for testing a limit at the boundary.
Free to use for testing, teaching and demos, commercially or not, with no attribution needed. A link back to this page is always appreciated.
Put it online
Have a TAR file? Give it a link.
Drop a .tar file on 99helpers and it gets its own download link, so you can hand over a whole folder without attachment limits. Anyone with the link downloads the archive exactly as you uploaded it.
Questions
TAR files, frequently asked
What is a .tar file?
An archive: many files and folders stored in one file, each with its name, permissions, owner and date. It isn't compressed; .tar.gz, .tar.bz2 and .tar.xz are compressed versions.
How do I open a .tar file?
Run tar -xf file.tar on Linux, macOS or Windows 10 and 11. You can also double-click it on macOS and in recent Windows 11, or use 7-Zip.
Does tar compress files?
No. A tar file is about the size of its contents plus 512 bytes per file. Add compression with tar -czf (gzip), -cjf (bzip2) or -cJf (xz).
What's the difference between TAR and ZIP?
ZIP compresses each file separately and has an index, so one file can be pulled out quickly. tar doesn't compress or index; compressed as a whole, it usually ends up smaller, and it keeps Unix permissions and links reliably.
Why is my tar file 10 KB when the contents are tiny?
tar pads archives to whole records of 10,240 bytes by default, after two 512-byte end-of-archive blocks. Compressed, that padding costs almost nothing.
Can I see what's in a tar file without extracting it?
Yes: tar -tvf archive.tar lists every entry with permissions, owner, size and date, and reads nothing to disk.
Is it safe to extract a tar file?
With current GNU tar or bsdtar, as a normal user, into an empty folder, it's reasonably safe. Hand-written extraction code and old libraries can be tricked by ../ paths and symbolic links into writing files elsewhere.
What does tar stand for?
Tape archive. It was written for Seventh Edition Unix in 1979 to copy files to magnetic tape.
Related formats
Other file types explained
Keep going
Related
Sources
- GNU tar manual: Controlling the archive format
- GNU tar manual: Basic tar format
- The Open Group: pax (POSIX ustar and pax interchange formats)
- Python documentation: tarfile and extraction filters
- Microsoft Learn: tar on Windows
Last reviewed 27 October 2026.