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★xtract into/dest(auto-detects gzip). Modern tar sniffs the compressor, so-zis often optional on extract.tar -tf archive.tar.gz # list without extractingList contents first — verify before you unpack. Add-vfor sizes/permissions.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 czfre-compresses the whole set together (solid) — great ratio, but you can't extract one file cheaply.
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 / zstd --decompress)★Zstandard gives near-gzip speed with better-than-gzip ratios, and decompresses very fast regardless of level — the best all-rounder for most new work.zstd -19 file · zstd --ultra -22 file # max ratio★Levels 1–19 (up to 22 with--ultra). Higher = smaller & slower to compress; decompression stays fast. Negative levels (--fast) trade ratio for raw speed.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.
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.