View all jar files contents in one go ?

I can view a jar file contents using the below command:

$ jar -tvf ./checker-compat-qual-2.0.0.jar
     0 Mon May 02 18:28:46 IST 2016 META-INF/
   184 Mon May 02 18:28:44 IST 2016 META-INF/MANIFEST.MF
     0 Mon May 02 17:20:16 IST 2016 afu/
     0 Mon May 02 17:20:16 IST 2016 afu/org/
     0 Mon May 02 17:20:16 IST 2016 afu/org/checkerframework/
     0 Mon May 02 17:20:16 IST 2016 afu/org/checkerframework/checker/
     0 Mon May 02 17:20:16 IST 2016 afu/org/checkerframework/checker/formatter/
  1042 Mon Feb 01 18:36:58 IST 2016 afu/org/checkerframework/checker/formatter/FormatUtil$Conversion.class

I can list all jar files using the below command:

$ find . -name '*.jar'
./com.google.collections.jar
./com.google.guava_1.6.0.jar
./hamcrest-core-1.2.jar
./json-20140107.jar
./junit.jar
./selenium-java.jar
./animal-sniffer-annotations-1.14.jar
./selenium-support-3.141.0.jar
./selenium-edge-driver-3.141.0.jar
./jsr305-1.3.9.jar

I wish to view the contents of all jar files in one go so i decided to merge both the command like below:

$ find . -name '*.jar' | xargs jar -tvf

However this does not yeild any output.

Can you please suggest what I should do to view the contents of all the files in one go ?

I'm on Redhat Linux centos 7

jar tvf can only take one archive as parameter, so try:

find . -name '*.jar' | xargs -n 1 jar tvf 

This will break if there are spaces in directory or file names

You could also try:

find . -name '*.jar' -exec jar tvf {} \;

Works !! Is it possible to print the jar file name incase i grep for the output like below:

find . -name '*.jar' -printf "%f%h" -exec jar tvf {} \; | grep -i 'org/openqa/selenium/WebDriver'

When the grep is found it found print the filename under which the jar tvf returned the grepped text.

Expected Output:

find . -name '*.jar' -printf "%f%h" -exec jar tvf {} \; | grep -i 'org/openqa/selenium/WebDriver'
Found in: /app/var/lib/okhttp-3.11.0.jar
   474 Fri Feb 01 00:00:00 IST 1985 org/openqa/selenium/WebDriver$ImeHandler.class
   331 Fri Feb 01 00:00:00 IST 1985 org/openqa/selenium/WebDriver$Navigation.class
  1049 Fri Feb 01 00:00:00 IST 1985 org/openqa/selenium/WebDriver$Options.class
   615 Fri Feb 01 00:00:00 IST 1985 org/openqa/selenium/WebDriver$TargetLocator.class
   360 Fri Feb 01 00:00:00 IST 1985 org/openqa/selenium/WebDriver$Timeouts.class
   534 Fri Feb 01 00:00:00 IST 1985 org/openqa/selenium/WebDriver$Window.class
  1305 Fri Feb 01 00:00:00 IST 1985 org/openqa/selenium/WebDriver.class
  7485 Fri Feb 01 00:00:00 IST 1985 org/openqa/selenium/WebDriverException.class
   725 Fri Feb 01 00:00:00 IST 1985 org/openqa/selenium/WebDriverInfo.class

Try:

find . -name '*.jar' -exec jar tf {} \; | grep -v '/$' | xargs grep -hil 'org/openqa/selenium/WebDriver'

Unfortunately this does not work for me Centos 7 Redhat Linux. I get the below error:

$ find . -name '*.jar' -exec jar tf {} \; | grep -v '/$' | xargs grep -hil 'com/google/common/collect/ImmutableMap'
grep: META-INF/MANIFEST.MF: No such file or directory
grep: META-INF/versions/9: No such file or directory
grep: META-INF/versions/9/module-info.class: No such file or directory
grep: org/openqa/selenium/AbstractCapabilities.class: No such file or directory
grep: org/openqa/selenium/Alert.class: No such file or directory
grep: org/openqa/selenium/Architecture$1.class: No such file or directory
grep: org/openqa/selenium/Architecture$2.class: No such file or directory
grep: org/openqa/selenium/Architecture$3.class: No such file or directory
grep: org/openqa/selenium/Architecture.class: No such file or directory

Indeed, that would only work if the files had already been deflated so that was not very helpful :slight_smile:

Try this instead:

find . -name '*.jar' -exec bash -c '\
result=$(zipgrep -HIli "org/openqa/selenium/WebDriver" {}) &&
printf "%s\n" "Found in: {}" "$result"' \;