Linux gunzip Command: Decompress gzip Files
gunzip decompresses .gz files compressed with gzip. Since it usually converts the compressed file back to the original file, you need to specify an option if you want to keep the .gz file.
What is the gunzip command?
gunzip is the decompression function of GNU gzip and is used for the same purpose as gzip -d. When you decompress only the gzip layer in tar.gz, a .tar archive remains. To extract all directories and members, you need to use the extraction function of tar.
Basic syntax
gunzip [options] file.gz [file.gz...]
The installed implementation and options may vary depending on the distribution. Check the description on your current system with man gunzip.
Examples
Decompressing a file
Restores report.log.gz to report.log. By default, the original compressed file is removed.
gunzip report.log.gz
Preserving the compressed file
Add -k when you need to check again or use it elsewhere.
gunzip -k report.log.gz
Extract to a separate file
Restore to standard output and save to a new file. Make sure not to overwrite an existing file with the same name.
gunzip -c report.log.gz > restored-report.log
How to Check After Decompression
gunzip decompresses files compressed with .gz and by default removes the compressed file. Prepare sample files in a separate working directory and then check them.
gunzip note.txt.gz ls -l note.txt
If successful, gunzip usually produces no output, and ls will show the restored note.txt. If a file with the same name already exists, it may ask whether to overwrite or fail.
gunzip -c note.txt.gz > newfile is useful for keeping the compressed file and writing the contents to another file. Do not assume that multiple files are combined in a single .gz. For .tar.gz, first understand the archive structure and check the list with tar -tzf.
Main Options and Format
| Options/Format | Description |
|---|---|
-k |
Keep the input compressed file. |
-c |
Send the restored data to standard output. |
-t |
Check for errors without creating a file by decompressing. |
-l |
Display the size and ratio of the compressed file, etc. |
-f |
Can force processing without confirmation, so be careful not to overwrite. |
Precautions when using
If a restoration target with the same name already exists, choose overwrite carefully. Shell redirection with -c > file can empty the existing file first. Individual files in gunzip cannot be extracted with .tar.gz alone, so use tar -xzf.
Frequently Asked Questions
If you run gunzip backup.tar.gz, will all the files be extracted?
No. Only the gzip compression is removed, usually leaving backup.tar. The files inside need to be extracted using tar.
Official Documentation
The exact behavior of options and differences depending on the implementation can be checked in the official gunzip documentation.









