Archives & CompressionCLI Reference
$gzip
Compress or expand files using Lempel-Ziv coding (LZ77).
Syntax DefinitionPOSIX standard
gzip [OPTIONS] [FILE...]Try `gzip` Live in Interactive Sandbox
Zero-install client simulation with real-time feedback.
bash — terminal
AST Sandbox (Free)
Overview & How gzip Works
`gzip` compresses individual files, replacing them with `.gz` extensions. It is the standard compression format across Linux for package distribution, web compression, and system log archiving.
Common Flags & Command Options
| Flag / Option | Description |
|---|---|
| -d, --decompress | Decompress files (same as gunzip). |
| -k, --keep | Keep (do not delete) original input files during compression. |
| -9, --best | Use maximum compression ratio (slower). |
Practical Real-World Examples
Example #1Compress a log file
gzip -k notes.txt && ls -l notes.txt*Compresses notes.txt to notes.txt.gz while preserving original notes.txt.
Sample Output:
-rw-r--r-- 1 user user 1200 notes.txt
-rw-r--r-- 1 user user 420 notes.txt.gzFrequently Asked Questions
Can gzip compress a directory directly without tar?
No, `gzip` only compresses individual files. To compress a whole folder, bundle it first with `tar` (producing a `.tar.gz`).