How can I search for a string in a folder that has zip files also

grepputtysearchunixzip

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.

Best Answer

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.

Related Question