Skip to content
Latchkey

zcat: View gzip Files Without Extracting

zcat decompresses a .gz file to stdout without touching disk, so you can grep or pipe compressed logs directly.

zcat is gunzip -c under a shorter name. In CI it inspects compressed logs and streams caches into tar without an intermediate file.

What it does

zcat reads one or more .gz files and writes their decompressed contents to stdout, equivalent to gunzip -c. On most systems it also reads the legacy .Z format. Nothing is written to disk, which is ideal for inspection and piping.

Common usage

Terminal
zcat app.log.gz | grep -c ERROR      # count without extracting
zcat backup.sql.gz | psql mydb       # restore straight from .gz
zcat data.tar.gz | tar -t            # list a tarball's contents
zcat part1.gz part2.gz > all.txt     # concatenate decompressed

Options

ItemWhat it does
zcat <file.gz>Decompress to stdout (like gunzip -c)
-f / --forceAlso pass through non-gzip input unchanged
multiple filesConcatenate all decompressed outputs
.Z supportReads legacy compress .Z on most systems

In CI

Use zcat to search rotated logs (app.log.1.gz) or to feed a compressed dump into a restore command without a scratch file. On systems where zcat is strict about the .gz suffix, add -f, or fall back to gunzip -c.

Common errors in CI

"gzip: stdin: not in gzip format" means the input is not gzip; use the matching viewer (xzcat, bzcat, zstdcat). On some minimal images zcat refuses names without .gz; add -f or use gunzip -c. A broken pipe when piping into head is normal and can be ignored.

Related guides

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