gunzip — Decompress gzip files
Linux / File and disk management / gunzip.html
Decompresses .gz files created by gzip back to their original content.
Basic Information
| Command Name | gunzip |
|---|---|
| One-line Introduction | Decompresses .gz files created by gzip back to their original content. |
| Provided by | GNU coreutils (installed by default on all Linux distributions) |
| Official Documentation | https://man7.org/linux/man-pages/man1/gzip.1.html |
| Supported Operating Systems | Linux, macOS, BSD, WSL |
| Installation Status | Installed by default (no separate installation needed) |
| Category | Linux file and disk management (tags: decompress, gzip, .gz) |
What is this command?
gunzip decompresses files in the gzip format (.gz). By default it restores the original file and removes the .gz archive.
It behaves like gzip -d, and when used with pipes it can decompress a stream without creating files.
What problems does it solve?
- You need to read the contents of a .gz file
- You are unpacking log archives for analysis
- You want to restore the original file name
- You need to decompress a stream through a pipe
Key features
Decompress a file
Expands the given .gz file back to the original.
- When to use: You received a compressed file
- What you get: A file with the original name
- Limitations: The .gz file is removed by default.
Keep the archive
-k keeps the compressed file.
- When to use: You must keep the archive as well
- What you get: Both the original and the archive
- Limitations: It uses twice the disk space.
Decompress to stdout
-c writes the result to the screen or a pipe.
- When to use: You only need the content or want to pipe it
- What you get: Decompressed output without new files
- Limitations: Binary output can garble the terminal.
Installation and usage
Check whether it is installed
gunzip --version
sudo apt install coreutils # Debian/Ubuntu sudo dnf install coreutils # Fedora
Real-world examples
Expand a file
Expand a log archive into the original file.
gunzip access.log.gz
Keep the archive
Decompress while keeping the archive.
gunzip -k backup.sql.gz
Preview content
Preview the start without creating files.
gunzip -c app.log.gz | head -n 20