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.
01Command
$ zcat app.log.2.gz | grep ERROR02What 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
04Undo
✓No undo needed — this command does not change persistent state.
05Sources
- gzip(1) - Linux manual pageEvidence: 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
dmesg prints kernel messages with seconds since boot by default; -T converts them to real dates and times.
Check how much space the binary journal consumes and permanently trim it by size, age, or file count.