tar -czf archive.tar.gz dir/★Create, gzip, to file. tar bundles the tree into one stream;zpipes it through gzip. Mnemonic: "create ze file."tar -xzf archive.tar.gz -C /dest · tar -tf archive.tar.gz★xtract into/dest(auto-detects the compressor);-tflists contents without extracting — verify before you unpack.tar -cJf a.tar.xz dir/ · tar --zstd -cf a.tar.zst dir/★Swap the compressor:-J=xz,-j=bzip2,--zstd=zstd (GNU tar). ⚠️tar czfcompresses the whole set together (solid) — great ratio, but you can't extract one file cheaply.tar -czg snapshot.snar -f backup.tgz /data # see card 5-g(--listed-incremental) turns tar into an incremental backup engine — covered in the Backup section.
zip -r archive.zip dir/ · unzip archive.zip -d /dest★zip compresses each file independently (random access to any entry) — the universal cross-platform choice, esp. on Windows. Weaker ratio than solid tarballs.gzip file # → file.gz (removes original) gunzip file.gz · gzip -k file # -k keeps original★gzip (DEFLATE) is the compatibility baseline — everywhere, single-file, streamable. ⚠️ It deletes the source by default; use-kto keep it.bzip2 file # → file.bz2 · better ratio, slower than gzipbzip2 (Burrows-Wheeler) beats gzip on ratio but is slow and largely superseded by zstd/xz today.
zstd file # → file.zst zstd -d file.zst # decompress (or: unzstd)★Zstandard gives near-gzip speed with better-than-gzip ratios, and decompresses very fast regardless of level — the best all-rounder for new work. CLI now uses multiple threads by default (up to 4).zstd -19 file · zstd --ultra -22 file · zstd --max file★1.5.7Levels 1–19 (up to 22 with--ultra); negative levels (--fast) trade ratio for speed. The new--maxmaximizes ratio at the cost of time/memory. High levels (18+) got much faster in 1.5.7.zstd -T0 --long -19 bigfile # all cores + long-range matching-T0uses every core;--longwidens the match window for large/repetitive files. ⚠️ Decompressing--longdata needs the same flag.zstd --train samples/* -o dict · zstd -D dict small.jsonDictionaries dramatically improve compression of many small, similar records — zstd's signature feature. Train once, reuse (large dicts can be memory-mapped).
xz -9 file # → file.xz · LZMA2, highest ratio, slow★xz/LZMA squeezes the most out of data — ideal for write-once archives & distro packages where compress time doesn't matter. Slow both ways, RAM-hungry at high levels.lz4 file # extremely fast, modest ratioLZ4 compresses/decompresses at GB/s — for hot paths, real-time streams, and DB internals where CPU, not size, is the constraint.brotli -q 11 file # → file.br · great for text/web assetsBrotli excels on text/HTTP responses (built-in dictionary) — standard forContent-Encoding: br. Snappy (like LZ4) is the fast in-datastore choice for Parquet/Cassandra.# already-compressed data (jpg, mp4, zip) barely shrinks — don't double-compressgotchaMedia & encrypted blobs are near-incompressible; re-compressing wastes CPU and can slightly grow the file. Store those as-is.