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.gztarballs - 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.