Skip to content

Linux Zgrep command explained

  • by
  • 2 min read

Photo: Jivacore/

The Linux terminal is famous for having hundreds if not thousands of small tools, utilities and commands that give users complete control of their system. On the flip side, this also means that users will have to deal with an exhaustive list of commands they need to know. 

In this article, we’re talking about the zgrep command in Linux, what they do, how are they used and everything that you need to know. 

Also read: How to exclude in Grep?

What is zgrep?

The zgrep command is used to search specific expressions in files that are in a compressed state. If this sounds rather similar to grep, that’s because all the parameters that apply to grep apply to zgrep as well. 

The general syntax for the command is as follows:

zgrep [grep options] Expression File name

The syntax mentioned above is divided into the following three parts:

  • Grep options: Flags that enable or control additional search features. 
  • Expression: The term or string that you want to search.
  • File: The file you want to search. Since we’re using zgrep, this is a compressed file like gz, bzip, zip, tgz, or tar among others. 

Also read: Vi Linux editor cheatsheet

Zgrep options

Here are some of the most commonly used zgrep options.

iUsed to ignore case sensitivity.
nShows the line number of the matched expression
vUsed to show lines that don’t have the search term/expression
eUsed to add multiple search expressions
oOnly shows the matched section of the line with the search expression
lShows the name of the file that contains the search expression
wOnly displays lines with the whole search expression
(zgrep shows results even if the search expression partially matches by default)
hShows the matched lines without the file name(s)

Also read: How to fix libGL error: failed to load driver: swrast?

Yadullah Abidi

Yadullah Abidi

Yadullah is a Computer Science graduate who writes/edits/shoots/codes all things cybersecurity, gaming, and tech hardware. When he's not, he streams himself racing virtual cars. He's been writing and reporting on tech and cybersecurity with websites like Candid.Technology and MakeUseOf since 2018. You can contact him here: