.TAR Tape Archive
.tar

Tape Archive

TAR (Tape Archive) bundles multiple files into a single archive preserving Unix permissions, ownership, and symlinks — without applying any compression. Pair with gzip, bzip2, or xz for compressed tarballs (.tar.gz, .tar.bz2, .tar.xz).

بنية الصيغة
Header magic bytes
Entries compressed files
Index directory
ArchiveNo CompressionUnix Permissions512-byte Blocks1979
بواسطة FileDex
غير قابل للتحويل

Tar archiving without recompression is possible but cross-format archive conversion is not available in browser WASM.

أسئلة شائعة

What is the difference between .tar and .tar.gz?

A .tar file is an uncompressed archive that bundles files while preserving Unix permissions. A .tar.gz file is a tar archive compressed with gzip, typically 60-80% smaller. TAR handles archiving; gzip handles compression. The two-step design lets you choose any compression algorithm independently.

Can Windows open TAR files natively?

Windows 10 (build 17063+) and Windows 11 include tar.exe in the command line. For GUI extraction, use 7-Zip (free) or WinRAR. Native File Explorer support for TAR was added alongside 7z and gz in the Windows 11 23H2 update.

Why does TAR not compress files?

TAR was designed in 1979 for sequential magnetic tape storage, where separating archiving from compression was architecturally necessary. Tapes are write-once sequential media — compression would prevent the tape drive from appending files. The separation also allows choosing the best compression algorithm (gzip, bzip2, xz, zstd) for the data type.

How do I extract a single file from a large tar.gz archive?

Run tar xzf archive.tar.gz path/to/specific/file.txt with the exact path as listed by tar tzf archive.tar.gz. Gzip archives must decompress sequentially from the start, so extracting one file still reads through the compressed stream up to that point.

ما يميز .TAR

What is a TAR file?

TAR (Tape Archive) is a Unix/Linux file archival format that combines multiple files and directories into a single file, preserving file permissions, ownership, timestamps, and symlinks. Originally designed for sequential magnetic tape storage at AT&T Bell Labs in the 1970s, TAR has become the standard packaging format for Unix software distribution and Linux system administration.

اكتشف التفاصيل التقنية

TAR itself performs no compression — it only bundles files. Compression is applied separately by piping through gzip, bzip2, or xz, producing the familiar .tar.gz, .tar.bz2, and .tar.xz formats (also called "tarballs"). The two-step design gives flexibility: you can choose the compression algorithm independently of the archive structure.

How to open TAR files

  • 7-Zip (Windows) — Free, supports all TAR variants
  • WinRAR (Windows) — Built-in TAR support
  • tar (macOS, Linux) — Built-in CLI tool: tar -xf archive.tar
  • The Unarchiver (macOS) — Free, handles .tar, .tar.gz, .tar.bz2
  • PeaZip (Windows, Linux) — Free, open-source

Technical specifications

Property Value
Compression None (archiving only — use with gzip/bzip2/xz)
Permissions Preserves Unix file permissions (chmod bits)
Ownership Preserves user/group ownership (UID/GID)
Symlinks Fully supported
Max path length 256 characters (GNU TAR extends with POSIX extensions)
Magic bytes 75 73 74 61 72 (ustar at offset 257)
Common pairs .tar.gz / .tgz, .tar.bz2 / .tbz2, .tar.xz / .txz

Common use cases

  • Linux software distribution: Source code releases as .tar.gz tarballs
  • System backup: Preserves file permissions and ownership, unlike ZIP
  • Docker images: Container filesystem layers are stored as TAR archives
  • Deployment packages: Application code bundled for Linux server deployment
  • Data transfer between Unix systems: Reliable, lossless file bundling with metadata

Essential TAR commands

# Create a .tar.gz archive (compress with gzip)
tar -czf archive.tar.gz /path/to/folder/

# Create a .tar.bz2 archive (compress with bzip2)
tar -cjf archive.tar.bz2 /path/to/folder/

# Create a .tar.xz archive (compress with xz — best ratio)
tar -cJf archive.tar.xz /path/to/folder/

# List contents without extracting
tar -tzf archive.tar.gz

# Extract to current directory
tar -xzf archive.tar.gz

# Extract to specific directory
tar -xzf archive.tar.gz -C /target/directory/

# Extract a single file
tar -xzf archive.tar.gz path/to/specific/file.txt

The flags: -c create, -x extract, -t list, -z gzip, -j bzip2, -J xz, -f file (must be last before filename), -v verbose.

TAR vs ZIP

Feature TAR ZIP
Compression External (separate step) Built-in per file
Unix permissions ✅ Preserved ❌ Mostly lost
Symlinks Limited
Native Windows support ❌ (needs 7-Zip) ✅ Built-in
Random access ❌ (sequential) ✅ (central directory)
Streaming ✅ (pipe-friendly) Limited

TAR is the right choice for Unix/Linux systems and any scenario where file permissions and ownership matter. ZIP is the better choice for cross-platform sharing with Windows users.

Incremental backups with TAR

GNU TAR supports incremental (snapshot) backups:

# Full backup with snapshot file
tar -czf backup-full.tar.gz --listed-incremental=snapshot.file /data/

# Incremental backup (only changed files since last snapshot)
tar -czf backup-incr.tar.gz --listed-incremental=snapshot.file /data/

This is widely used in cron-based backup scripts as a lightweight alternative to dedicated backup software.

TAR and Docker

Docker stores image layers as TAR archives internally. The docker save and docker export commands produce .tar files. Understanding TAR helps when working with container registries, inspecting image contents, or building minimal base images from scratch using tar -c . | docker import - myimage.

المرجع التقني

نوع MIME
application/x-tar
Magic Bytes
75 73 74 61 72 ustar magic at offset 257 in POSIX tar.
المطوّر
AT&T Unix
سنة التقديم
1979
معيار مفتوح
نعم
000001017573746172 ustar

ustar magic at offset 257 in POSIX tar.

البنية الثنائية

A TAR file is a sequence of 512-byte blocks. Each archived file begins with a 512-byte header block followed by the file data padded to a 512-byte boundary. The header contains the filename (bytes 0-99, null-terminated), file mode (bytes 100-107, octal ASCII), owner/group UID/GID (bytes 108-115 and 116-123, octal ASCII), file size (bytes 124-135, octal ASCII), modification time (bytes 136-147, octal ASCII Unix timestamp), header checksum (bytes 148-155, octal ASCII), type flag (byte 156: '0'=regular file, '5'=directory, '2'=symlink), and link name (bytes 157-256). The POSIX/UStar magic signature 'ustar' appears at offset 257-261 (hex: 75 73 74 61 72), followed by a version field at 263-264. The extended UStar fields include owner name (bytes 265-296), group name (bytes 297-328), device major/minor (bytes 329-336 and 337-344), and a filename prefix (bytes 345-499) that extends the 100-byte filename limit to 256 characters. Two consecutive 512-byte blocks of all zeros mark the end of the archive. There is NO magic number at offset 0 — bytes 0-99 contain the first file's pathname.

OffsetLengthFieldExampleDescription
0x00 100 bytes File Name src/main.c (null-padded) Null-terminated ASCII filename. Limited to 100 bytes in original tar; UStar prefix field extends this to 256.
0x64 8 bytes File Mode 30 31 30 30 36 34 34 00 (0100644) Octal ASCII file permissions including file type bits. e.g., 0100644 = regular file, owner rw, group/other r.
0x6C 8 bytes Owner UID 30 30 30 31 30 30 30 00 (0001000) Octal ASCII numeric user ID of the file owner.
0x74 8 bytes Group GID 30 30 30 31 30 30 30 00 (0001000) Octal ASCII numeric group ID.
0x7C 12 bytes File Size 30 30 30 30 30 30 30 34 32 36 34 00 (00000004264) Octal ASCII file size in bytes. Directories and symlinks have size 0.
0x88 12 bytes Modification Time 31 34 37 31 33 30 35 36 37 32 00 00 (14713056720) Octal ASCII Unix timestamp (seconds since 1970-01-01).
0x94 8 bytes Header Checksum 30 31 32 33 34 35 00 20 (012345) Octal ASCII sum of all header bytes (checksum field treated as spaces during calculation).
0x9C 1 byte Type Flag 30 (ASCII '0' = regular file) '0'=regular file, '2'=symlink, '5'=directory, 'L'=GNU long name, 'x'=PAX extended header.
0x101 5 bytes UStar Magic 75 73 74 61 72 (ustar) POSIX UStar format indicator at offset 257. GNU tar variant uses 'ustar \0' (with trailing spaces). Absent in very old V7 tar archives.
0x107 2 bytes UStar Version 30 30 (00) UStar version number. POSIX.1-2001 uses '00'.
1979tar command introduced in Unix Version 7 (V7) at AT&T Bell Labs for magnetic tape archival1988POSIX.1-1988 standardizes the UStar format with the 'ustar' magic at offset 2572001POSIX.1-2001 (IEEE Std 1003.1) publishes the PAX extended header format, supporting unlimited filename length and UTF-82013Docker adopts TAR as the internal format for container image filesystem layers2017GNU tar 1.29+ adds zstd compression support (--zstd flag)
Create a tar archive from a directory أخرى
tar cf archive.tar folder/

c creates a new archive, f specifies the output filename. No compression is applied — the archive size equals the sum of all file sizes plus header overhead.

Extract a tar archive to the current directory أخرى
tar xf archive.tar

x extracts files, f reads from the named archive. Add -v for verbose output listing each extracted file. Use -C /target/dir/ to extract to a different directory.

List tar archive contents without extracting أخرى
tar tf archive.tar

t lists all entries (files, directories, symlinks) in the archive without extracting. Add -v for detailed output including permissions, owner, size, and modification time.

Create a compressed tar.gz archive أخرى
tar czf archive.tar.gz folder/

z pipes the tar stream through gzip compression. Replace z with j for bzip2 (.tar.bz2) or J for xz (.tar.xz). f must be the last flag before the filename.

TAR ZIP transcode lossless ZIP is universally supported on Windows, macOS, and Linux without third-party tools. Converting TAR to ZIP enables cross-platform file sharing with Windows users who lack tar support, at the cost of losing Unix permissions and symlinks.
TAR TAR.GZ transcode lossless Adding gzip compression to an uncompressed TAR archive reduces file size by 60-80% for text-heavy content. The .tar.gz format is the standard for Linux software distribution and source code releases.
متوسط

نقاط الضعف

  • Path traversal: crafted tar entries with ../../ prefix can write files outside the extraction directory, overwriting system files or planting executables in PATH directories
  • Symlink attacks: a tar archive can contain a symlink pointing to /etc/passwd followed by a regular file with the same name — naive extractors follow the symlink and overwrite the target
  • Tar bomb: an archive without a top-level directory extracts hundreds of files directly into the current directory, polluting the working directory and potentially overwriting existing files

الحماية: FileDex does not extract TAR archives server-side. All format analysis is reference-only. When extracting untrusted tar files locally, always use --one-top-level (GNU tar 1.28+) to force extraction into a single subdirectory, and use --no-same-owner to prevent UID/GID spoofing.

GNU tar أداة
Standard tar implementation on Linux with GNU extensions (long names, incremental backups)
Default tar on macOS and FreeBSD, supports tar/zip/7z/cpio via libarchive
node-tar مكتبة
Node.js tar library used by npm for package installation
archiver مكتبة
Node.js streaming archive generator for tar and zip
7-Zip أداة
Windows archiver with full TAR read/write support