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.

Category
Troubleshooting · Servers & Linux
Time
5–15 min
Last reviewed
What you'll need
  • SSH or shell access to the Linux server
  • Path to the .gz file

Step-by-step diagnostic

Step 1 of 7
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 -h and 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.gz and compare to expected if known. Truncated files are often smaller.
  • Re-download from the original source or restore from backup. Run gzip -t file.gz on 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 with df -h before 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/output or gunzip -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.gz exits 0 with no output.
  • Decompression completes without error.
  • df -h shows sufficient free space for the operation.

Escalation ladder

Work from the device outward. Stop when the problem is fixed.

  1. Test integrity Run gzip -t to confirm whether the archive is valid.
  2. Check disk space Verify free space with df -h; free space or use another filesystem.
  3. Handle corruption Re-download or restore from backup; retest with gzip -t.
  4. 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.

Run `gzip -t file.gz`. Good: no output (exit 0)—archive is valid; check disk space or permissions. Bad: error such as "unexpected end of file"—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.

Run `df -h` and check the Avail column for the filesystem. Good: sufficient free space—retry gzip; if it still fails, check permissions. Bad: 0 or very low space—free space or decompress to another filesystem.

You can change your answer later.

Retry gzip

Retry the original gzip or gunzip command. If it still fails, check permissions and inodes with ls -l and df -i.

Free space or use another filesystem

Free disk space (remove files, clear logs) or decompress to a filesystem with space: `gzip -dc file.gz > /path/on/other/fs/output`. Confirm free space with df -h before retrying.

Can you re-download or restore the file?

A corrupted file must be replaced. Re-download from source or restore from backup.

Re-download the archive or restore from backup. Run `gzip -t file.gz` on the new copy. Good: test passes—proceed with decompression. Bad: test still fails—source may be bad; escalate.

You can change your answer later.

Re-download or restore and retest

Obtain a fresh copy. Run gzip -t. If it passes, decompress. If it still fails, the source is bad—escalate.

Escalate

The archive repeatedly fails after re-download, or you cannot free disk space. Contact your administrator or add storage.