Fastest way to grep jar file for a particular name in it

findgrep

I am trying to find all the jars which has spring in its name. I am working with windows and using cygwin to run the linux commands. Does my below command looks right?

find . -name "*.jar" -exec jar tf '{}' \| grep -H "spring" \;

For some reason, it is still processing and haven't got the result on the screen. Any fast way to grep the jar file with a particular name?

For example, below are the valid jar files which has spring in it –

spring-web.jar
spring-core.jar
test-spring.jar 

Best Answer

I do not believe the jar command accepts multiple .jar files by way of arguments so AFAIK a single jar invocation addressing all .jar files is out of the question. One option to speed things up by avoiding one find exec invocation for each .jar file is the follows

find . -name '*.jar' -exec sh -c \
'for f; do  jar -tf "$f" | grep --label="$f" "spring"; done' sh {} +
Related Question