Skip to content
Latchkey

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

Terminal
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 compression

Options

FlagWhat it does
-d / --decompressDecompress (same as gunzip)
-k / --keepKeep the input file
-c / --stdoutWrite to stdout, do not modify input
-1 .. -9Compression level (fast .. best)
-l / --listShow 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.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →