Compressed files are like tiny suitcases. They save space. They travel fast. But at some point, you need to open them. That is where the gunzip command comes in. It is a small Linux and Unix tool that unpacks files ending in .gz.
TLDR: Use gunzip file.gz to unzip a .gz file. For example, gunzip logs.gz turns it into logs. If a server stores 30 days of logs and each compressed file is 70% smaller, gunzip helps you quickly inspect old data without wasting disk space. Use gunzip -c file.gz if you want to view or redirect the output without deleting the original file.
What Is Gunzip?
gunzip means “GNU unzip.” It is part of the gzip package. Its job is simple. It takes a compressed .gz file and restores the original file.
For example:
gunzip report.txt.gz
This creates:
report.txt
By default, gunzip removes the compressed file. So report.txt.gz disappears after decompression. Do not panic. That is normal.
Think of it like opening a snack bag. Once opened, the sealed bag is gone. The snack remains.
Basic Gunzip Syntax
The basic format is short and friendly:
gunzip [options] file.gz
Here is the simplest example:
gunzip data.csv.gz
This unzips data.csv.gz into data.csv.
You can also unzip several files at once:
gunzip file1.gz file2.gz file3.gz
That saves time. Your fingers will thank you.
Common Gunzip Examples
1. Unzip One File
gunzip backup.sql.gz
This gives you:
backup.sql
Use this when you have one file and want the normal result.
2. Keep the Original .gz File
By default, gunzip deletes the compressed file. If you want to keep it, use -k.
gunzip -k archive.gz
Now you get both files:
archive.gzarchive
This is great when you are nervous. Or careful. Both are valid moods.
3. Write Output to the Screen
Use -c to send the uncompressed content to standard output.
gunzip -c access.log.gz
This prints the file content in your terminal. It also keeps the original .gz file.
You can combine it with less:
gunzip -c access.log.gz | less
This is perfect for large log files. You can scroll without creating a new file.
4. Extract to a New File Name
gunzip does not have a direct “save as” option. But you can use -c and redirect the output.
gunzip -c oldname.gz > newname.txt
This keeps oldname.gz and creates newname.txt.
5. Test a Compressed File
Want to check if a .gz file is healthy? Use -t.
gunzip -t download.gz
If the file is fine, you usually see no output. Silence is good here. Very zen.
To see a message, add -v:
gunzip -tv download.gz
6. Use Verbose Mode
The -v option tells gunzip to talk more.
gunzip -v logs.gz
It shows useful info, such as the compression ratio and file names.
Useful Gunzip Options
Here are the options you will use most often:
-k: Keep the original compressed file.-c: Print output to the terminal or redirect it.-v: Show more details.-t: Test the compressed file.-f: Force decompression.-r: Work recursively through directories.-l: List information about compressed files.
Example with -l:
gunzip -l server.log.gz
This can show the compressed size, uncompressed size, ratio, and file name. It is like checking the suitcase label before opening it.
Gunzip vs Gzip -d
You may see this command too:
gzip -d file.gz
It does the same thing as:
gunzip file.gz
In many systems, gunzip is just a friendly shortcut for gzip -d. Use whichever you like. Both open the same magic box.
Working With .tar.gz Files
Here is a common trap. A file named archive.tar.gz is not just one file. It is a tar archive that was compressed with gzip.
If you run:
gunzip archive.tar.gz
You get:
archive.tar
But that is still an archive. You must extract it with tar:
tar -xvf archive.tar
Or do both steps at once:
tar -xzvf archive.tar.gz
That command is often the better choice for .tar.gz files.
Troubleshooting Common Gunzip Problems
Problem: “not in gzip format”
This means the file is not really a gzip file. The name may end in .gz, but the content says, “Nope.”
Check the file type:
file mystery.gz
If it says ZIP, tar, HTML, or plain text, use the right tool for that format.
Problem: “No such file or directory”
The file name or path is wrong. First, list files:
ls
Or search for it:
find . -name "*.gz"
File names are case-sensitive. Data.gz and data.gz are not the same.
Problem: “Permission denied”
You may not have permission to read or write in that folder.
Try checking permissions:
ls -l file.gz
If needed, use a folder where you have access. Or ask your system admin. Bring snacks. It helps.
Problem: File Already Exists
If the output file already exists, gunzip may ask before overwriting it.
To force overwrite, use:
gunzip -f file.gz
Be careful. -f is powerful. It does not care about your feelings.
Problem: Disk Is Full
Decompressed files can be much larger. A 200 MB .gz file may become a 1 GB log file.
Check disk space first:
df -h
If space is low, use -c with tools like less, grep, or head instead of fully extracting.
gunzip -c huge.log.gz | grep "ERROR"
This searches inside the compressed file without creating the full output file.
Practical Use Case
Imagine you manage a small app server. It creates one compressed log file per day. Each file is 50 MB compressed and 250 MB when opened. That is an 80% space saving.
One morning, users report errors from last Tuesday. You do not need to unzip every log. You can run:
gunzip -c app-tuesday.log.gz | grep "ERROR"
Fast. Clean. No giant files left behind. Your server stays happy.
Best Practices
- Use
-kwhen you want a safe backup. - Use
-cfor quick viewing or searching. - Use
-tbefore extracting downloads from unknown sources. - Check disk space before opening huge files.
- Use
tar -xzvffor.tar.gzarchives.
Final Thoughts
gunzip is small, fast, and very useful. It does one job and does it well. Once you know gunzip file.gz, gunzip -k file.gz, and gunzip -c file.gz, you can handle most daily tasks.
So the next time you meet a .gz file, do not glare at it. Smile. Type a tiny command. Let gunzip open the suitcase.

