Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

zgrep multiple gz files in directory

Tags:

grep

bash

I have problem executing zgrep command for looking for word in the directory where I have almost 1000 *.gz files.

I am trying with:

find /var/www/page/logs/ -name "*.gz" -exec zgrep '/index.php' {} \;

result is:

GET : '/index.php'
GET : '/index.php'
GET : '/index.php'

And it works.I get list of occurance of index.php with no file name where it was found. It is kind of useless for me unless i knew in which files (filename) it appears.

How can i fix it?

like image 222
Mithrand1r Avatar asked Feb 04 '14 09:02

Mithrand1r


1 Answers

You could supply the -H option to list the filename:

find /var/www/page/logs/ -name "*.gz" -exec zgrep -H '/index.php' {} \;

If you wanted only the list of matching files, use -l:

find /var/www/page/logs/ -name "*.gz" -exec zgrep -l '/index.php' {} \;
like image 153
devnull Avatar answered Sep 29 '22 05:09

devnull