Luke Oliff.

TIL: Reading Gzip Files Without Decompressing With zcat

·TIL·1 min read·Luke Oliff

Compressed log files save disk space but add friction. zcat reads them without explicit decompression.

zcat server.log.gz | grep "ERROR"

Decompresses the gzip file to stdout and pipes it through grep. The original .gz file stays compressed.

zcat access.log.2025-10-01.gz | head -50

Read the first 50 lines of a compressed log file. Find out if this is the right file before decompressing the whole thing.

zcat *.gz | sort -u > all-unique-errors.txt

Merge and deduplicate across multiple compressed files. The pipeline works as if the files were already decompressed.

What is the difference between zcat and gunzip -c?

None. zcat is equivalent to gunzip -c on most systems. On some systems zcat expects a .Z extension. Use gunzip -c for compatibility.

Is zcat available on macOS?

Yes. zcat is part of the BSD compression utilities built into macOS.