Open In App

zgrep command in Linux with Examples

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Share
Report issue
Report

The zgrep command is used to search out expressions from a given a file even if it is compressed. All the options that applies to the grep command also applies to the zgrep command. 

Syntax:  

zgrep [grep options] Expression File name

Options: 

  • -c : This option is used to display the number of matching lines for each file. 
    Example: 
zgrep -c "linux" GFG.txt.gz

  • -i : This option is used to ignore case sensitivity. 

    Example: 

zgrep -i "LINUX" GFG.txt.gz

  • -n : This option is used to display the line number of file if the given expression is present in the line. 
    Example: 
zgrep -n "linux" GFG.txt.gz

  • -v : This option is used to display the lines which doesn’t have the expression present in it. Basically invert the search function. 
    Example: 
zgrep -v "linux" GFG.txt.gz

  • -e : This option is used to specify the expression but can be used multiple times. 
    Example: 
zgrep -e "linux" -e "Linux" GFG.txt.gz

  • -o : This option is used to display only the matched section of the line from the given expression. 
    Example: 
zgrep -o "linux" GFG.txt.gz

  • -l : This option is used to display the names of the files with the expression present in it. 
    Example: 
zgrep -l "linux" *

  • -w : By default, zgrep command displays lines even if the expression is found as a sub-string. This option only displays lines only if the whole expression is found. 
    Example: 
zgrep -w "linux" GFG.txt.gz

  • -h : This option is used to display the matched lines but doesn’t display the file names. 
    Example: 
zgrep -h "linux" GFG.txt.gz


Last Updated : 16 Nov, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads