gzip: Compress Files with -9, -k, -c in CI
gzip compresses each input file to a .gz file with DEFLATE, replacing the original unless you keep it with -k or write to stdout with -c.
gzip is the default single-file compressor on every runner. The knobs you actually use in CI are the level (-9), keeping the source (-k), and streaming to stdout (-c).
What it does
gzip compresses each named file, appends .gz, and by default deletes the original. gunzip (or gzip -d) reverses it. It handles one logical stream per file; use tar first to bundle a directory, then gzip.
Common usage
gzip -9 app.log # max compression, replaces app.log
gzip -k -9 build.tar # keep the original (.tar stays)
gzip -c report.txt > report.txt.gz # stream, keep source
gzip -d report.txt.gz # decompress (same as gunzip)Options
| Flag | What it does |
|---|---|
| -9 / --best | Maximum compression (slowest); -1 is fastest |
| -k / --keep | Keep the input file instead of deleting it |
| -c / --stdout | Write to stdout, leave the source in place |
| -d / --decompress | Decompress (equivalent to gunzip) |
| -r / --recursive | Recurse into directories |
| -f / --force | Overwrite an existing .gz output |
In CI
gzip is single-threaded. For large artifacts on a multi-core runner, pigz (parallel gzip) produces the same .gz format far faster; drop it in as a replacement. Use -k so a later step can still read the uncompressed file.
Common errors in CI
"gzip: stdin: not in gzip format" on decompress means the file is not gzip (often it is xz, zstd, or plain text); check with file. "gzip: <name>.gz already exists" fails the step unless you add -f. "gzip: <name>: No such file or directory" is a wrong path or a glob that did not expand.