File Compression Algorithms
What's the difference between `.tar`, `.gz`, and `.tar.gz`? Our guide defines file compression and covers the most popular algorithms on Linux.
Use compression algorithms to reduce the size of your digital files and folders. The main goals of compression are to save storage space, speed up file transfers, and simplify file organization by bundling multiple files or folders into one archive.
In practice, compression allows you to:
- Store more data on the same disk.
- Transfer files faster over networks.
- Organize multiple files, and/or folders into a single, portable package.
- Preserve file attributes like permissions and ownership (when using archive tools like TAR)
Parameters / Features
| Format | Purpose | Compression | Common OS | Notes |
| TAR | Bundles multiple files | None | Linux/Unix | No size reduction; often used before compression |
| Gzip (.gz) | Compresses single files | Yes (Gzip) | Linux/Unix | Uses DEFLATE algorithm |
| TAR.GZ / TGZ | Bundles + compresses | Yes (Gzip) | Linux/Unix | Common for backups |
| ZIP | Bundles + compresses | Yes | Windows, Linux, Mac | Widely supported |
| BZ2 (.bz2) | Compresses single files | Yes (Bzip2) | Linux/Unix | Better compression than Gzip but slower |
Examples
TAR:
tar -cvf archive.tar my_folder- Creates an archive with no compression.
Gzip:
gzip file.txt- Compresses file.txt into file.txt.gz.
TAR.GZ:
tar -czvf archive.tar.gz my_folder- Bundles and compresses a folder into one file.
ZIP:
zip -r archive.zip my_folder- Creates a compressed zip archive.
Bzip2:
bzip2 file.txt- Compresses a file with better ratios than Gzip.
Common Use Cases
- Backups: Archiving folders into .tar.gz or .tgz files.
- Cross-platform sharing: Using .zip for compatibility across Windows, macOS, and Linux.
- Disk space savings: Compressing large log files with Gzip or Bzip2.
- Data transfer efficiency: Sending compressed files over the internet to reduce upload/download times.
Reference Links
How to Use Tar, GZIP, & Zip in Linux