View all jar files contents in one go ?


Login or Register for Dates, Times and to Reply

 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting View all jar files contents in one go ?
# 1  
View all jar files contents in one go ?

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

Code:
$ 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:

Code:
$ 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:

Code:
$ 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
# 2  
jar tvf can only take one archive as parameter, so try:
Code:
find . -name '*.jar' | xargs -n 1 jar tvf

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

You could also try:
Code:
find . -name '*.jar' -exec jar tvf {} \;


Last edited by Scrutinizer; 2 Weeks Ago at 05:33 AM..
# 3  
Quote:
Originally Posted by Scrutinizer
jar tvf can only take one archive as parameter, so try:
Code:
find . -name '*.jar' | xargs -n 1 jar tvf

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

You could also try:
Code:
find . -name '*.jar' -exec jar tvf {} \;

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

Code:
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:

Code:
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

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

# 5  
Quote:
Originally Posted by Scrutinizer
Try:
Code:
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:

Code:
$ 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

# 6  
Indeed, that would only work if the files had already been deflated so that was not very helpful Smilie

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

Login or Register for Dates, Times and to Reply

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #205
Difficulty: Easy
Routing Information Protocol (RIP) runs over Transmission Control Protocol (TCP).
True or False?

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

View file contents created by dbCAmplicons as tab delimited

I have run the following command : od -c Results_May18.fixrank | head Here is the result. I wanted the results in tab delimited. Thanks $ od -c Results_May18.fixrank | head 0000000 M 0 1 6 0 1 : 1 2 9 : 0 0 0 0 0 0000020 0 0 0 0 - A T T D Y ... (2 Replies)
Discussion started by: Benard
2 Replies

2. Shell Programming and Scripting

How to get CRC check sum of files in java EAR file without extracting .jar/.war files to disk.?

unzip -v gives CRC info of each file in a zip(in my case .EAR) file. # unzip -v my-application.ear Archive: my-application.ear Length Method Size Cmpr Date Time CRC-32 Name -------- ------ ------- ---- ---------- ----- -------- ---- 197981 Defl:N 183708 7%... (1 Reply)
Discussion started by: kchinnam
1 Replies

3. UNIX for Advanced & Expert Users

Using vim to view the contents of a directory

When I use this command: vi /home/bob/.vimI expect to see. " ============================================================================ " Netrw Directory Listing (netrw v149) " /home/bob/.vim " Sorted by name " Sort sequence:... (4 Replies)
Discussion started by: cokedude
4 Replies

4. Shell Programming and Scripting

trying to view contents of an existing script

root#pwd /opt/tools root# cat check_traffic /opt/tools/utils/commands $1 /opt/tools/utils/DIR/check_traffic root# cat /opt/tools/utils/DIR/check_traffic gew "check_traffic -v" Hi above script works for checking traffic for an ip address im trying to view the check_traffic script by... (5 Replies)
Discussion started by: slashbash
5 Replies

5. HP-UX

[Solved] How to view the contents of the .depot files

Hi, I have one depot file. I would want to view the contents of this file with out extracting and with out installing in a machine. Like for $rpm -qlp rpmfilename will list out all the files in a rpm. Like I would want a command to view the files from a .depot file. I tried with swlist... (2 Replies)
Discussion started by: skmdu
2 Replies

6. Solaris

Differences between jar files

I want to find the difference between two jar files sitting on a sun box. How do I do this? (3 Replies)
Discussion started by: runnerpaul
3 Replies

7. Linux

Crontab not recognizing the jar files

Hi All, I am using crontab which execute a shell script. In the shell script, I am executing a java program. This Java program requires the jar files. The cron job file ' cronfile.txt ' contents: MAILTO="raju_utla@dcis.uohyd.ernet.in" 0-59 * * * *... (3 Replies)
Discussion started by: rajuutla
3 Replies

8. Programming

view contents of shared library

Hi , i have two doubts in Hp-Ux 1) How to View objects or contents in a shared library in HP-Ux 2) Can i added a c object file to the existing shared file from a different directory . for example : I have two directories X and Y I have a.o b.o c.o object files in X directory I... (4 Replies)
Discussion started by: naren_chella
4 Replies

9. UNIX for Dummies Questions & Answers

Unable to view contents of a directory

Hi, first post here be gentle. Very new to Unix. Using HP-UX 10.20 I CD into a remote directory on one machine $ cd /net/remote hostname yet when I do an ll in this directory none of the contents appear. It just is empty. when I do the same command from another machine, $ cd... (13 Replies)
Discussion started by: maddave
13 Replies

Featured Tech Videos