2009-06-04

Find a file inside a zip

Brutally simple shell script I often use to find a class file that I know exists somewhere in a directory tree full of jar files (but generally useful for finding files somewhere in a directory tree of zips):

#!/bin/bash                                                                             
                                                                                        
for zip in $*                                                                           
do                                                                                      
  echo $zip                                                                             
  for file in $(unzip -Z -1 $zip)                                                       
  do                                                                                    
    echo "$zip:$file"                                                                   
  done                                                                                  
done
I put this in a file called zipdump, then do things like this:
find -name "*.jar" | xargs zipdump | grep SomeClass
And get:
./some/random/path/foo.jar:com/google/whatever/SomeClass.class

AddThis Social Bookmark Button

1 comment:

  1. I love the shell. This is excellent stuff!

    ReplyDelete