Compression
gzip
Compress files using the Lempel-Ziv coding algorithm (LZ77).
Synopsis
syntax
gzip [OPTION]... [FILE]...
Examples
Compress file (replaces original with file.txt.gz)
gzip file.txt
Best compression, keep original
gzip -k -9 large.log
Decompress file
gzip -d file.txt.gz
Recursively compress all files in directory
gzip -rv logs/
Common options
| Flag | Description |
|---|---|
| -d | Decompress |
| -k | Keep original file |
| -v | Verbose — show compression ratio |
| -r | Recurse into directories |
| -1 to -9 | Compression level (1=fast, 9=best) |
About gzip
The `gzip` command compress files using the Lempel-Ziv coding algorithm (LZ77). Compression commands reduce file sizes for storage and transfer.
Linux supports multiple compression formats, each with different speed and ratio trade-offs. Understanding these tools is essential for working with archives, backups, log rotation, and software distribution packages.
The command accepts 5 commonly used flags shown above, though the full set of options is available in the man page (`man gzip`). The 4 examples on this page cover typical real-world usage patterns that you can copy and adapt for your own workflows.
Related commands
More Compression Commands
Other commands in the Compression category