Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

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.

share|improve this answer
    
+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 –  MariusMatutiae Oct 23 '13 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 '13 at 17:34
    
@MariusMatutiae Yep. Here it was. And here. –  Rik Oct 23 '13 at 17:39
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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