Skip to main content
TAR (Tape Archive) is a Unix standard archive format that stores multiple files and directories while preserving file metadata and permissions.

Format Overview

TAR provides:
  • No compression - Pure archiving format
  • Unix metadata preservation - Permissions, ownership, timestamps
  • Unlimited size - No file size restrictions
  • Symbolic link support - Full Unix file system support
  • Device file support - Character and block devices
  • Sparse file support - Efficient sparse file handling
TAR itself does not provide compression. It’s typically combined with GZIP (.tar.gz), BZIP2 (.tar.bz2), or XZ (.tar.xz) for compressed archives.

Format Structure

From source/CPP/7zip/Archive/Tar/TarHeader.h:11-17, TAR uses fixed-size 512-byte records:
Each file entry consists of:
  1. Header - 512 bytes containing metadata
  2. Data - File content, padded to 512-byte blocks

Header Structure

File Types

TAR supports various file types (TarHeader.h:47-73):

Extended Types

GNU TAR and PAX formats add:
  • kGnu_LongName (‘L’) - Long filename (>100 chars)
  • kGnu_LongLink (‘K’) - Long link name
  • kPax (‘x’) - POSIX.1-2001 extended header
  • kGlobal (‘g’) - Global extended header

TAR Variants

USTAR Format

The POSIX standard TAR format (TarHeader.h:83-84):

PAX Format

Modern POSIX.1-2001 format supporting:
  • Unlimited filename length
  • Unlimited file size
  • Extended attributes
  • High-precision timestamps

Usage Examples

Create TAR Archive

Creates uncompressed TAR archive.

Create TAR.GZ (GZIP Compressed)

Or in one step:

Create TAR.BZ2 (BZIP2 Compressed)

Create TAR.XZ (XZ Compressed)

XZ compression typically provides the best compression ratio for TAR archives, while GZIP is fastest. BZIP2 offers a middle ground.

Extract TAR Archive

Extracts all files preserving directory structure.

Extract TAR.GZ Archive

Or simply:

List TAR Contents

Shows file list with permissions and sizes.

Preserving Unix Metadata

File Permissions

TAR stores full Unix permissions (rwxrwxrwx):
On Windows, 7-Zip maps Windows attributes to Unix permissions:
  • Read-only → r--
  • Normal → rw-
  • Executable → rwx
TAR preserves symbolic links:
The -snl option ensures symbolic links are stored as links, not as file copies.

Timestamps

TAR stores modification time with second precision. Extended formats (PAX) support nanosecond precision.

Advanced Features

Long Filenames

Standard TAR limits filenames to 100 characters. GNU TAR and PAX support unlimited lengths:

Sparse Files

GNU TAR efficiently handles sparse files:
Sparse files with large zero regions are stored efficiently.

Incremental Backups

GNU TAR supports incremental backups:
TAR stores hard links efficiently:
Hard links reference the same data block, saving space.

Compression Comparison

Same Dataset (1 GB source files)

Compression ratios and times vary significantly based on data type and system performance.

Implementation Details

TAR handler implementation:

Best Practices

For Linux/Unix Systems

Use TAR for maximum compatibility:

For Cross-Platform

TAR.GZ offers best compatibility:

For Large Archives

Use XZ compression for best ratio:

For Fast Backup

Use GZIP for speed:

Common Patterns

Backup with Timestamp

Extract Specific Files

Exclude Patterns

Limitations

TAR format limitations:
  • No built-in compression (must use external compression)
  • No encryption support
  • No error recovery or redundancy
  • Limited metadata on non-Unix systems
  • Standard TAR limited to 8 GB files (fixed in PAX/GNU)

Compatibility Notes

Windows

7-Zip handles TAR on Windows but:
  • File permissions are approximated
  • Symbolic links require admin privileges or Developer Mode
  • Device files are ignored

Linux/macOS

Full TAR support including:
  • All file types
  • Complete permission preservation
  • Extended attributes (with PAX format)

Archive Tools

TAR compatibility:
  • 7-Zip - Full support for GNU TAR and PAX
  • GNU tar - Reference implementation
  • BSD tar - Full POSIX TAR and PAX support
  • Windows tar - Basic support (Windows 10+)

See Also