zgrep
Quick Reference
Command Name:
zgrep
Category:
file management
Platform:
Linux/Unix
Basic Usage:
Common Use Cases
Syntax
zgrep [options] pattern [file...]
Options
The zgrep command accepts the same options as the regular grep command, since it's a wrapper around grep for compressed files:
Option | Description |
---|---|
-A NUM |
Print NUM lines of trailing context after matching lines |
-B NUM |
Print NUM lines of leading context before matching lines |
-C NUM |
Print NUM lines of output context |
-c |
Print only a count of matching lines per file |
-E |
Interpret pattern as an extended regular expression (equivalent to zegrep) |
-F |
Interpret pattern as a fixed string (equivalent to zfgrep) |
-i |
Ignore case distinctions |
-l |
Print only names of files with matches |
-n |
Print line number with output lines |
-v |
Select non-matching lines |
Supported File Formats
The zgrep command can handle various compressed file formats:
Extension | Format |
---|---|
.gz |
gzip compressed files |
.Z |
compress (LZW) compressed files (on some systems) |
Examples
How to Use These Examples
The examples below show common ways to use the zgrep
command. Try them in your terminal to see the results. You can copy any example by clicking on the code block.