zgrep
TLDR
Search for pattern in gzipped file
SYNOPSIS
zgrep [grep-options] [-e] pattern [file...]
DESCRIPTION
zgrep searches for patterns in gzip-compressed files without manual decompression. It's equivalent to gunzip -c file.gz | grep pattern but more convenient.
The tool automatically detects whether files are compressed and handles them appropriately. This makes it safe to use on directories containing mixed compressed and uncompressed files.
zgrep supports the same options as grep, including basic and extended regular expressions. For explicit regex modes, use zegrep (extended) or zfgrep (fixed strings).
Multiple files can be searched, with filenames shown by default when multiple files match.
PARAMETERS
-i
Case-insensitive matching-n
Show line numbers-l
List filenames with matches only-c
Count matching lines-v
Invert match (show non-matching lines)-h
Suppress filename in output-r, -R
Recursive search-E
Extended regular expressions (like egrep)-F
Fixed string matching (like fgrep)-e pattern
Specify pattern
CAVEATS
Only gzip compression is supported natively. For other formats:
- bzip2: use bzgrep
- xz: use xzgrep
- zstd: pipe through zstdcat
Large compressed files must be fully decompressed to search, using CPU and potentially significant memory.
On some systems, zgrep is a wrapper script that may have slightly different behavior than native grep.


