The Wayback Machine - https://web.archive.org/web/20230512160215/https://www.geeksforgeeks.org/zgrep-command-in-linux-with-examples/
Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App
geeksforgeeks
Browser
Continue

Related Articles

zgrep command in Linux with Examples

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

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

My Personal Notes arrow_drop_up
Last Updated : 16 Nov, 2021
Like Article
Save Article
Similar Reads