gunzip Command
Beginner Compression & Archives man(1)Decompress .gz files
👁 9 views
📅 Updated: Mar 15, 2026
SYNTAX
gunzip [OPTION]... [FILE]...
What Does gunzip Do?
gunzip decompresses files compressed with gzip. It is equivalent to gzip -d. gunzip replaces the .gz file with the decompressed original by default.
gunzip can also decompress files created by compress (.Z files) and pack (.z files). It handles multiple files and supports keeping the original compressed file.
For viewing compressed files without decompressing, use zcat (or zless, zgrep) instead.
gunzip can also decompress files created by compress (.Z files) and pack (.z files). It handles multiple files and supports keeping the original compressed file.
For viewing compressed files without decompressing, use zcat (or zless, zgrep) instead.
Options & Flags
| Option | Description | Example |
|---|---|---|
| -k | Keep compressed file | gunzip -k file.gz |
| -f | Force decompression (overwrite existing) | gunzip -f file.gz |
| -r | Recursively decompress | gunzip -r /var/log/ |
| -l | List compressed file info | gunzip -l file.gz |
| -v | Verbose output | gunzip -v file.gz |
| -c | Write to stdout (keep original) | gunzip -c file.gz > file.txt |
Practical Examples
#1 Decompress file
Decompresses to access.log, removing the .gz file.
$ gunzip access.log.gz#2 Keep original
Decompresses while keeping the .gz file.
$ gunzip -k backup.sql.gz#3 Decompress to stdout
Decompresses and shows first 10 lines without creating a file.
$ gunzip -c data.csv.gz | head -10#4 Decompress all in directory
Decompresses all .gz files recursively.
$ gunzip -r /var/log/old/#5 Force overwrite
Decompresses even if the output file already exists.
$ gunzip -f file.gzTips & Best Practices
zcat for viewing: Use zcat file.gz to view contents without decompressing. Or zless for paging, zgrep for searching.
gunzip = gzip -d: gunzip is exactly the same as gzip -d. Use whichever you remember.
Replaces .gz file: gunzip removes the .gz file by default. Use -k to keep it.
Frequently Asked Questions
How do I decompress a .gz file?
gunzip file.gz or gzip -d file.gz. Both work identically.
How do I view a .gz file without decompressing?
Use zcat file.gz to display contents. Or zless file.gz for paged viewing.
How do I keep the .gz file after decompressing?
Use gunzip -k file.gz. The -k flag keeps the compressed file.
Related Commands
More Compression & Archives Commands
Master Linux with Professional eBooks
Curated IT eBooks covering Linux, DevOps, Cloud, and more
Browse Books →