Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bash command: search for class in file system of jars

I'm wanting to recursively search my maven repository (an n folder deep heirachy of jars) for a specific class inside an unknown jar.

jar -tvf myJar.jar | grep ClassIWant.class works great for a known jar but I'm having problems piping/chaining bash commands to achieve a recursive search.

Any hints much appreciated.

Related: BASH :: find file in archive from command line

like image 327
markdsievers Avatar asked Dec 07 '22 01:12

markdsievers


2 Answers

find -name \*.jar | xargs -n1 -iFILE sh -c "jar tvf FILE | sed -e s#^#FILE:#g" | grep classIWant\\.class | cut -f1 -d:
like image 192
gawi Avatar answered Dec 30 '22 19:12

gawi


Bash 4+

shopt -s globstar
for file in **/*.jar
do
  jar -tvf "$file" | grep ....
done

<4++

find /path -type f -name "*.jar" | while read -r FILE
do
     jar -tvf "$FILE" | grep ....
done
like image 24
ghostdog74 Avatar answered Dec 30 '22 20:12

ghostdog74