gzip command
Compress or decompress single files with gzip.
- Archives & compression
- Package gzip
- 6 options · 7 examples
Syntax
gzip [options] [file…]Provided by the gzip package. Run man gzip for the full manual.
Common options
| Option | What it does |
|---|---|
-d | Decompress (same as gunzip) |
-k | Keep the original file |
-r | Compress files in directories recursively |
-1 … -9 | Speed vs size (default 6) |
-l | Show compression ratio |
-c | Write to standard output |
Examples
Compress a file (replaces it)
gzip access.logKeep the original
gzip -k dump.sqlDecompress
gunzip access.log.gzDecompress and keep the .gz
gzip -dk file.gzBest compression
gzip -9 data.csvRead a .gz file without extracting
zcat access.log.gz | lessCompress a database dump on the fly
mysqldump mydb | gzip > mydb.sql.gz
No example matches. Check the options table or search the guides.
gzip guides
- How to Extract tar.gz File in Linux Linux Commands · Updated Apr 2025
- How to Unzip (Extract) a GZ File in Linux Linux Commands · Updated Apr 2025
