Read and Search .gz Files Without Decompressing (zcat/zgrep)

Log rotation compresses old logs to .gz; zcat, zless, and zgrep let you pipe, page, and search them directly.

LinuxlogszgrepgzipLow risk
Run `zcat file.gz | grep ERROR` or `zgrep ERROR file.gz` to search inside a gzip file without extracting it.

01Command

Command
$ zcat app.log.2.gz | grep ERROR

02What it does

The z-prefix family maps to ordinary tools: zcat = cat, zless = less, zgrep = grep, zdiff = diff — all work on the compressed stream in memory. When you do need to decompress, `gunzip -k file.gz` keeps the original .gz (the -k is what people forget; plain gunzip deletes it). For the same trick across formats, xz has xzgrep and zip/unzip offer -p or -Z for piping.

03Risk

RiskLow risk
Requirementsgzip installed (default)

04Undo

✓No undo needed — this command does not change persistent state.

05Sources

  • gzip(1) - Linux manual page
    Ubuntu Manpages · technical · 2026-09-17
    Evidence: The gzip package provides zcat, zless, and zgrep to view or search compressed files without decompressing; gunzip -c and gzip -k decompress while keeping the original.

Last verified: 2026-09-17 · Category: Files & Folders

06Related solutions