zgrep

Search gzip-compressed files for patterns

TLDR

Search for pattern in gzipped file
$ zgrep "[pattern]" [file.gz]
Case-insensitive search
$ zgrep -i "[pattern]" [file.gz]
Show line numbers
$ zgrep -n "[pattern]" [file.gz]
Search recursively in compressed files
$ zgrep -r "[pattern]" [directory]
Count matching lines
$ zgrep -c "[pattern]" [file.gz]
Show only filenames with matches
$ zgrep -l "[pattern]" [*.gz]

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

INSTALL

sudo apt install gzip
sudo dnf install gzip
sudo pacman -S gzip
sudo apk add gzip
sudo zypper install gzip
brew install gzip
nix profile install nixpkgs#gzip

CAVEATS

Only gzip compression is supported natively. For other formats:- bzip2: use bzgrep- xz: use xzgrep- zstd: pipe through zstdcatLarge 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.

SEE ALSO

grep(1), zegrep(1), zfgrep(1), zcat(1), gzip(1), bzgrep(1)