tar.gz explained: why Linux uses two tools for one job
Haven Zip team · · 2 min read
Windows users see .zip. Linux and macOS users see .tar.gz, .tgz, .tar.xz and lately .tar.zst, and wonder why one file needs two extensions. The answer is a design philosophy from the 1970s that turned out to be more flexible than the all-in-one approach, at the cost of one real inconvenience.
Two jobs, two tools
tar, short for tape archive, dates from 1979. Its only job is to concatenate files and directories into one stream, preserving names, permissions, ownership, symbolic links and timestamps. It does not compress anything. Its output is exactly as large as the inputs plus a 512-byte header per file.
Compression is a separate step. gzip (1992) compresses a single stream with Deflate, the same algorithm ZIP uses. Pipe tar into gzip and you get .tar.gz. Swap gzip for xz and you get .tar.xz, smaller but slower. Swap it for zstd and you get .tar.zst, nearly as small as xz and many times faster.
What the split buys
Because the whole archive is one compressed stream, the compressor sees every file at once and shares its dictionary across all of them. A source tree with a thousand similar files compresses far better than the same tree in a ZIP, where each file is compressed alone. This is the same advantage as a solid 7z archive.
It also means any compressor can be plugged in, now or in the future, without touching tar. When zstd arrived in 2016, tar.zst worked the same day.
What it costs
There is no index. To list the files or extract one file from the end of a tar.gz, the reader has to decompress everything before it. Browsing a large tar.gz is slower than browsing a ZIP of the same content, and extracting a single file can take as long as extracting all of them. Haven Zip streams through the archive to build the tree, which is why a big tar.xz takes a moment to open while a big ZIP opens instantly.
Permissions and ownership are preserved faithfully, which is exactly what you want when packaging software for Linux and exactly what you do not care about when sending photos to a relative on Windows.
- Sharing with Windows or non-technical users: ZIP.
- Source code, backups, Linux packages: tar.gz for compatibility, tar.zst for speed, tar.xz for the smallest file.
- Have a tar.gz and need a ZIP: Haven Zip converts it on your device.