Skip to content
Latchkey

compress and uncompress: Legacy .Z Files

compress writes the legacy .Z (LZW) format and uncompress reads it; on Linux both are provided by the ncompress package.

You meet .Z when handling old Unix vendor tarballs (man pages, Solaris packages). Modern runners often lack compress, so knowing the ncompress install and the gzip fallback saves the job.

What it does

compress applies LZW and appends .Z, replacing the original; uncompress reverses it. gzip and zcat can also read .Z, so on a runner without compress you can still decompress with gunzip or zcat. The format is obsolete but persists in legacy artifacts.

Common usage

Terminal
compress -c data.txt > data.txt.Z    # -c writes to stdout
uncompress legacy.tar.Z              # -> legacy.tar
zcat old.man.Z | less                # zcat reads .Z too
gunzip -c archive.Z > archive        # gzip handles .Z

Options

FlagWhat it does
-cWrite to stdout, keep the source
-dDecompress (compress -d equals uncompress)
-rRecurse into directories
-vVerbose, report the ratio
-fForce overwrite of existing output

In CI

If compress/uncompress are missing, install ncompress (apt-get install -y ncompress). For decompression only, you often do not need it at all: gunzip and zcat read .Z natively, so gunzip -c file.Z is a zero-install fallback. Do not choose .Z for new artifacts; gzip or zstd are strictly better.

Common errors in CI

"compress: command not found" or "uncompress: command not found" means ncompress is not installed. "<file>.Z: not in compressed format" means the input is not LZW .Z. If only decompressing, skip the install and use gunzip -c or zcat, which both handle .Z.

Related guides

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