30

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

Ariyan
  • 2,056
  • 3
  • 27
  • 36

1 Answers1

36

Try:

for f in *.zip; do echo "$f: "; unzip -l $f | grep <filename>; done
Paulo Tomé
  • 3,754
  • 6
  • 26
  • 38
tripledes
  • 1,207
  • 9
  • 9
  • 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 ; done` Thank you again. – Ariyan Aug 08 '12 at 23:31
  • 3
    for f in *.zip; do unzip -l $f | grep && echo $f; done ... Better this way ? :) – tripledes Aug 08 '12 at 23:34
  • bash: syntax error near unexpected token `;' – mjaggard Sep 29 '15 at 11:24
  • Also fails on filenames with a space in them if I put the code into a script – mjaggard Sep 29 '15 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 – Yordan Georgiev Sep 23 '16 at 06:25
  • Just recommend to set `unzip -l "$f"` with quotation marks so there is no issue with files with spaces... – wittich Mar 16 '22 at 13:36