Decompress Gzip Files
The gunzip command is used to decompress files that were compressed with gzip. It's the counterpart to the gzip command and restores compressed files to their original form. By default, gunzip removes the compressed file after successful decompression.
| Option | Description |
|---|---|
-k |
Keep original compressed file |
-f |
Force decompression, overwrite existing files |
-t |
Test compressed file integrity |
-v |
Verbose mode - show compression ratios |
-l |
List compressed file information |
-c |
Write output to stdout, keep original file |
-r |
Recursively decompress directories |
-q |
Quiet mode - suppress warnings |
| Extension | Description | Example |
|---|---|---|
.gz |
Standard gzip format | file.txt.gz |
.Z |
Compress format | file.txt.Z |
.tgz |
Gzipped tar archive | archive.tgz |
.tar.gz |
Gzipped tar archive | archive.tar.gz |
-t to test file integrity before decompression-c with pipes to avoid creating temporary files-k to keep originals when disk space allows-f explicitly)gzip -d insteadgzip - Compress files with gzipzcat - View compressed files without extractingzless - Page through compressed filestar - Archive and extract tar filesunzip - Extract ZIP archives7z - Handle 7-Zip archives-k option: gunzip -k filename.gz. This keeps the original .gz file while creating the decompressed version.
gunzip -c filename.gz to output the decompressed content to stdout, or use zcat filename.gz which is equivalent and more commonly used for this purpose.
gunzip is actually a script or link to gzip -d. Both decompress gzip files with the same options and behavior.
gunzip -t filename.gz to test the file integrity. If the file is valid, no output is shown. If corrupted, an error message will be displayed.