Key facts
- Gzip compresses exactly one file with DEFLATE; to bundle several files you need tar first, giving .tar.gz.
- MIME type is application/gzip; files start with the bytes 1F 8B.
- The trailer stores a CRC-32 and the original size (modulo 4 GB), so gzip -t can detect corruption.
- The same compression is used for HTTP Content-Encoding: gzip on web servers.
- Created by gzip, logrotate, mysqldump pipelines and backup scripts.
How to open a .gz file
Open it with 7-Zip and extract the file inside. For a .tar.gz, the built-in tar -xzf file.tar.gz command also works.
Double-click to decompress it with Archive Utility, or run gunzip -k file.gz in Terminal to keep the original.
Run gunzip -k file.gz to decompress, or zcat file.gz and zless file.gz to read it without unpacking.
Common problems and fixes
- "gzip: file.gz: not in gzip format"
- The file is not gzip, despite the name: it may be plain text, a ZIP or an HTML error page. Run file file.gz to check the real type.
- "unexpected end of file"
- The file is truncated from an interrupted transfer. Download or copy it again; zcat can still print the readable start if you need partial data.
- "crc error" or "invalid compressed data"
- The compressed bytes are damaged. Run gzip -t file.gz to confirm, then restore it from the source or another backup.
- gunzip deleted my original .gz file
- That is gunzip's default behaviour. Use gunzip -k (keep) or zcat file.gz > file to leave the compressed copy in place.
Often converted to or from: TAR.GZ, ZIP, XZ, BZ2, plain file