kmail.at
contact

elsewhere

EnglishEN
← learning

linux · difficulty ◆

gzip — compress and decompress files

Make files smaller, save space, ship them faster.

Almost every file you have ever downloaded traveled in gzip form — yet gzip is also the tool that once shipped a 300% speedup by deleting a single line of code.

fully AI-generatedThis text is fully AI-generated and was published without human editorial review.

2026-08-12 · 4 min read

$ gzip
1.12
version here

gzip 1.12

1992
released

Gailly & Adler

DEFLATE
algorithm

LZ77 + Huffman

-1 .. -9
levels

default -6

What it does

gzip compresses a single file using the DEFLATE algorithm (LZ77 plus Huffman coding). It replaces the file with a compressed copy ending in .gz — you usually pair it with tar to compress whole directory trees.

Why it matters

Almost every download you grab is gzip-compressed at some layer: .tar.gz source archives, HTTP Content-Encoding, and system logs that rotate into .gz files. Knowing gzip means you can inspect and shrink files anywhere on a Unix box.

Example

$ gzip notes.txt
$ ls
notes.txt.gz
$ gzip -l notes.txt.gz
         compressed        uncompressed  ratio uncompressed_name
                420                1024  59.0% notes.txt

Compresses notes.txt in place, leaving notes.txt.gz. -l lists the compression ratio.

$ gzip -d notes.txt.gz
$ ls
notes.txt
$ cat notes.txt
hello from the terminal

-d decompresses, restoring the original file. You can also use gunzip.

Common flags

-d
decompress instead of compress (alias: gunzip)
-k
keep the original file after compressing/decompressing
-c
write to stdout instead of a file, so you can pipe it
-l
list compression ratio and sizes for a .gz file
-t
test the integrity of a compressed file
-1 .. -9
set compression level, -1 fastest, -9 best ratio (default -6)

History

Origin

gzip was released by Jean-loup Gailly and Mark Adler in 1992, replacing the older compress tool whose LZW compression was patented. Its DEFLATE format became the foundation for the PNG image format and zlib.

Fun fact

The name stands for 'GNU zip'. GNU tar can pipe straight into gzip, which is why '.tar.gz' archives are sometimes whimsically called 'tarballs'.

Under the hood

DEFLATE, the algorithm

gzip wraps the DEFLATE compression scheme, which is two stages: LZ77 finds repeated sequences and replaces them with back-references, then Huffman coding assigns shorter codes to frequent symbols. It is lossless — decompression reconstructs the exact original bytes.

The patent story

gzip exists because the older compress tool used LZW, which was covered by a Unisys patent. Gailly and Adler wrote a free, patent-free replacement in 1992. The same DEFLATE scheme became the foundation of the PNG image format and zlib, and it is still how HTTP shrinks the web today.

Fun facts

Pros & cons

pros

  • + Fast compression and near-universal decompression support
  • + Lossless — original bytes are always recoverable exactly
  • + The default everywhere: HTTP Content-Encoding, .tar.gz, rotated logs
  • + Levels let you trade speed for ratio on a per-file basis

cons

  • − Weakest ratio of the common modern compressors (xz, zstd, bzip2 beat it)
  • − Compresses a single file only — you must pair with tar for trees
  • − Old LZW-derived tools had patent issues that gzip was built to escape

Takeaways

  1. 1Compress: `gzip -k file.txt` keeps the original; plain `gzip` replaces it
  2. 2Decompress: `gunzip file.gz` or `gzip -d`
  3. 3Inspect a .gz without extracting: `gzip -l file.gz` shows the ratio
  4. 4Pipe compressed output: `cat file | gzip -c > file.gz`
  5. 5Reach for xz or zstd when you need a smaller file and speed matters less

Related commands

archive entry — written and published by a scheduled job, never editorially reviewed. Kept for reference: out of the site’s search index, and no ads run here. the reviewed library →

← all learning