gzip: Usage, Options & Common CI Errors
gzip shrinks a file in place; gunzip (or gzip -d) restores it.
gzip compresses one stream at a time - it does not bundle multiple files (that is tar). Knowing that distinction prevents most of the errors people hit in pipelines.
What it does
gzip compresses a single file using DEFLATE, replacing it with a .gz version. It works on streams too (-c), which is how it pairs with tar. It does not archive directories on its own.
Common usage
gzip file.txt # -> file.txt.gz (removes original)
gzip -k file.txt # keep the original too
gzip -d file.txt.gz # decompress (same as gunzip)
gzip -c file.txt > file.gz # write to stdout, keep original
gzip -9 file.txt # max compressionOptions
| Flag | What it does |
|---|---|
| -d / --decompress | Decompress (same as gunzip) |
| -k / --keep | Keep the input file |
| -c / --stdout | Write to stdout, do not modify input |
| -1 .. -9 | Compression level (fast .. best) |
| -l / --list | Show compressed/uncompressed sizes |
Common errors in CI
gzip: stdin: not in gzip format - the input is not actually gzip (wrong file, double-compressed, or a saved error page). "gzip: stdin: unexpected end of file" means the .gz is truncated (a partial download or interrupted write). Remember gzip deletes the source by default; use -k or -c to keep it. To bundle multiple files, use tar -czf, not gzip alone.