Skip to content
Latchkey

tar -z: gzip Compression (Usage & CI Errors)

tar -z pipes the archive through gzip on the way in or out.

gzip is the default compression for CI artifacts and caches: broad support, good ratio, fast enough. The -z flag wires gzip into tar without a separate pipe.

What it does

tar -z runs the archive through gzip on create and gunzip on extract, producing or reading a .tar.gz (also written .tgz). On extract, modern tar auto-detects gzip so -z is often optional, but it is required on create to actually compress.

Common usage

Terminal
tar -czf out.tar.gz dir/         # create gzip archive
tar -xzf out.tar.gz              # extract (z optional on GNU/BSD)
tar -czf - dir/ | ssh host 'cat > backup.tgz'
GZIP=-9 tar -czf out.tar.gz dir/  # max compression via gzip env

Options

FlagWhat it does
-z / --gzipFilter through gzip/gunzip
-a / --auto-compressPick the filter from the archive suffix (GNU)
-I "gzip -9"Use a custom compressor program (GNU --use-compress-program)
GZIP env varPass default flags to gzip (e.g. GZIP=-9)

In CI

When you control both ends, gzip is a safe default. For a versioned suffix, GNU tar -caf out.tgz dir/ uses -a to pick gzip from the .tgz name automatically, so renaming the output also changes the compressor.

Common errors in CI

gzip: stdin: not in gzip format means -z was used on a non-gzip file; drop -z or fix the input. gzip: stdin: unexpected end of file with tar: Unexpected EOF in archive means the .tar.gz is truncated, almost always a partial download; re-fetch and verify the byte count or checksum before extracting.

Related guides

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