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
Fromsource/CPP/7zip/Archive/Tar/TarHeader.h:11-17, TAR uses fixed-size 512-byte records:
- Header - 512 bytes containing metadata
- 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
Create TAR.GZ (GZIP Compressed)
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
Extract TAR.GZ Archive
List TAR Contents
Preserving Unix Metadata
File Permissions
TAR stores full Unix permissions (rwxrwxrwx):- Read-only →
r-- - Normal →
rw- - Executable →
rwx
Symbolic Links
TAR preserves symbolic links:-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:Incremental Backups
GNU TAR supports incremental backups:Hard Links
TAR stores hard links efficiently:Compression Comparison
Same Dataset (1 GB source files)
| Format | Archive Size | Compression Time | Extraction Time |
|---|---|---|---|
| .tar | 1000 MB | 10s | 8s |
| .tar.gz | 350 MB | 60s | 20s |
| .tar.bz2 | 320 MB | 120s | 40s |
| .tar.xz | 280 MB | 180s | 30s |
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
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+)