I am trying to search a string in a folder "test".

This folder has sub folders and zip files too. I want to search within this directory to find the match.

I used

zgrep '11:57' test
zgrep '11:57' test

But I could not got the result.

can some one tell the exact command for it.

1 Answer 1


You need to specify the files you want to be checked so in this case you should use:

zgrep '11:57' test/*

But you also want sub-directories. For this you need to include the find-command.

find . -print0 | xargs -0 zgrep '11:57'

Edit: I didn't use the find -exec cmd {} option here because according to this blog and this topic -exec runs a separate instance of your command for every find. Especially with lots of files this is not efficient. One pipe to xargs and xargs makes sure it runs your command as few times as possible which is often just once.

  • +1 but this command can be improved by using ... find -type -f -exec zgrep '11:57' {} \; The option -f restricts the match to files, and there is no need for a pipe Oct 23, 2013 at 17:30
  • I especially didn't specify the -exec option (and used xargs) because i read somewhere that with the -exec option zgrep is executed separate for every file/directory. With the xargs it should be executed only once. (I could be wrong here?)
    – Rik
    Oct 23, 2013 at 17:34
  • @MariusMatutiae Yep. Here it was. And here.
    – Rik
    Oct 23, 2013 at 17:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.