Compression

zgrep

Search inside compressed files without decompressing them first.

Synopsis

syntax
zgrep [OPTION]... PATTERN [FILE]...

Examples

Search rotated compressed logs
zgrep 'error' /var/log/syslog.*.gz
Case-insensitive search in compressed log
zgrep -i 'timeout' access.log.gz
Count 404s per compressed log file
zgrep -c '404' access.log.*.gz

Common options

FlagDescription
-iCase-insensitive
-cCount matches
-lList matching files
-nShow line numbers
-hSuppress filename prefix

About zgrep

The `zgrep` command search inside compressed files without decompressing them first. Compression commands reduce file sizes for storage and transfer.

Linux supports multiple compression formats, each with different speed and ratio trade-offs. Understanding these tools is essential for working with archives, backups, log rotation, and software distribution packages.

The command accepts 5 commonly used flags shown above, though the full set of options is available in the man page (`man zgrep`). The 3 examples on this page cover typical real-world usage patterns that you can copy and adapt for your own workflows.

Related commands

More Compression Commands

Other commands in the Compression category

Related tools