31

Possible Duplicate:
Find recursively all archive files of diverse archive formats and search them for file name patterns

I need to search for a file in all zip files in a directory.

Is there a tool like find that be able to search in ZIP files?

I tried this:

find /path/ -iname '*.zip' -print -exec unzip -l {} \; |grep -i '<filename>' 

But this only prints path of file in zip file and not the zip file name itself!

Thanks

2
  • That's why I added the 'echo' to my command. Commented Aug 8, 2012 at 23:28
  • for f in *.zip; do echo "$f: "; less $f | grep <filename>; done, according to: superuser.com/questions/216617/… Commented Jun 25, 2022 at 16:36

1 Answer 1

36

Try:

for f in *.zip; do echo "$f: "; unzip -l $f | grep <filename>; done 
6
  • Hi; Thanks; Your command makes lots of mass output (because of file date,... that ls prints)! but changing it to this solved the problem: for f in *.zip; do echo "$f: "; unzip -l $f | grep -i <file_name>; done Thank you again. Commented Aug 8, 2012 at 23:31
  • 3
    for f in *.zip; do unzip -l $f | grep <filename> && echo $f; done ... Better this way ? :) Commented Aug 8, 2012 at 23:34
  • bash: syntax error near unexpected token `;' Commented Sep 29, 2015 at 11:24
  • Also fails on filenames with a space in them if I put the code into a script Commented Sep 29, 2015 at 11:30
  • the same thing , but IMHO more user-friendly : while read -r zip_file ; do echo $zip_file ; unzip -l $zip_file | grep -i --color=always -R $to_srch; done < <(find . -name '*.zip') | less -R Commented Sep 23, 2016 at 6:25

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.