Skip to content
Latchkey

gzip Command Reference for CI Scripts

gzip shrinks a file in place; gunzip (or gzip -d) restores it.

gzip compresses one stream at a time and does not bundle multiple files (that is tar). Knowing that distinction prevents most of the errors people hit in pipelines.

Common flags/usage

  • -d / --decompress: decompress (same as gunzip)
  • -k / --keep: keep the input file instead of replacing it
  • -c / --stdout: write to stdout and leave the input alone
  • -1 .. -9: compression level, fast to best
  • -l / --list: show compressed and uncompressed sizes

Example

shell
gzip -k coverage.xml          # keep original, create coverage.xml.gz
gzip -dc logs.gz | grep ERROR
gzip -9 "report-${GITHUB_RUN_ID}.txt"

In CI

gzip deletes the source by default, so use -k or -c when you still need the original. "unexpected end of file" means the .gz is truncated (a partial download or interrupted write). To bundle multiple files use tar -czf, not gzip alone.

Key takeaways

  • gzip works on one file and removes the original unless you pass -k or -c.
  • Use tar -czf to compress directories; gzip alone does not bundle files.
  • "unexpected end of file" signals a truncated archive, often a failed download.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →