Fix gzip that fails
We'll test the archive with gzip -t, rule out disk space and permissions, then handle corrupted files by re-downloading or restoring from backup.
What you'll need
- SSH or shell access to the Linux server
- Path to the .gz file
Step-by-step diagnostic
Quick triage — pick your path
Quick triage — pick your path
Choose the option that matches what you see. You can jump straight to that section.
- Test archive integrity You want to confirm whether the file is corrupted before doing anything else.
- Check disk space You saw "No space left on device" or suspect full disk.
- Handle corrupted file gzip -t fails and you need to re-download or restore.
- When to escalate The archive still fails after re-download or you cannot free disk space.
Show full guide
Steps
Goal: Confirm the error, test integrity with gzip -t, rule out disk space, then handle corrupted files.
- Run the gzip command that failed and note the exact error. Common: “unexpected end of file” (truncated), “invalid compressed data” (corruption), “No space left on device” (full disk).
- Good: You have the error message. Proceed to Test archive integrity.
- Bad: No clear error—re-run the command and capture output.
Test archive integrity
Goal: Confirm whether the .gz file is valid using gzip -t.
- Run
gzip -t file.gz. No output and exit 0 means the archive is valid. Any error means the file is corrupted or truncated. - Good: Test passes—proceed to Check disk space.
- Bad: Test fails—proceed to Handle corrupted file.
Check disk space
Goal: Rule out full disk as the cause of gzip failure.
- Run
df -hand check the Avail column for the filesystem where you are working. Gzip needs free space for decompression (roughly the uncompressed size) or compression. - Good: Sufficient space—retry gzip; if it still fails, check permissions and inodes.
- Bad: 0 or very low space—see Free disk space or Decompress elsewhere.
Handle corrupted file
Goal: Replace a corrupted archive by re-downloading or restoring from backup.
- Check file size with
ls -l file.gzand compare to expected if known. Truncated files are often smaller. - Re-download from the original source or restore from backup. Run
gzip -t file.gzon the new copy. - Good: Test passes—decompress. Bad: Test still fails—source may be bad; escalate.
Free disk space
Goal: Free space when the filesystem is full.
- Run
du -sh *in the target directory to find large files. Remove unneeded files, clear logs, or move data. Confirm withdf -hbefore retrying gzip.
Decompress elsewhere
Goal: Decompress to a filesystem that has space when the current one is full.
- Run
gzip -dc file.gz > /path/on/other/fs/outputorgunzip -c file.gz > /path/on/other/fs/output. Confirm the output file is created.
When to escalate
- The archive repeatedly fails gzip -t after re-download (source may be bad).
- You cannot free disk space and no other filesystem is available.
- When to call a pro or contact your administrator; add storage if needed.
Verification
gzip -t file.gzexits 0 with no output.- Decompression completes without error.
df -hshows sufficient free space for the operation.
Escalation ladder
Work from the device outward. Stop when the problem is fixed.
- Test integrity Run gzip -t to confirm whether the archive is valid.
- Check disk space Verify free space with df -h; free space or use another filesystem.
- Handle corruption Re-download or restore from backup; retest with gzip -t.
- Escalate Bad source or no way to free space—contact administrator or add storage.
What to capture if you need help
Before calling support or posting for help, have these ready. It speeds everything up.
- Exact gzip error message
- Output of gzip -t
- Output of df -h and df -i
- File size (ls -l) and expected size
- Steps already tried
Does gzip -t pass on the file?
Run gzip -t file.gz. No output means success; an error means the file is corrupted or truncated.
You can change your answer later.
Is there enough disk space?
Gzip needs free space for decompression or compression. Check with df -h.
You can change your answer later.
Retry gzip
Free space or use another filesystem
Can you re-download or restore the file?
A corrupted file must be replaced. Re-download from source or restore from backup.
You can change your answer later.
Re-download or restore and retest
Escalate
Reviewed by Blackbox Atlas
Rate this guide
Was this helpful?
Thanks for your feedback.