The below command would look for the jar files that have substring spring
in it.
find /some/dir -type f -name "*spring*.jar"
Now, your original command looks through the content, which isn't what the text around it or the examples say.
find . -name "*.jar" -exec jar tf '{}' \| grep -H "spring" \;
Please find this chat description where Gilles explains why the above command is not what you are looking for.
Testing
[root@keithpc check]# cd jar_check/
[root@keithpc jar_check]# ls
[root@keithpc jar_check]# touch spring1.jar
[root@keithpc jar_check]# touch 1spring.jar
[root@keithpc jar_check]# touch no_sss_spring.jar
[root@keithpc jar_check]# touch spring.txt
Output:
[root@keithpc jar_check]# find ./ -type f -name "*spring*.jar"
./no_sss_spring.jar
./1spring.jar
./spring1.jar
As you can see, the spring.txt
file is not returned which I believe is what you are looking for.
Now, to understand what your command does,
- First I have created a java file which has the name as
springtest
.
- Now, I create the
class
file by running the java
command on the
java
file.
- Now, I add it to the jar file by running the jar command.
Now, when I run your command, it will return me the class
file
rather than the jar file that you are looking for.
[root@keithpc jar_check1]# javac springtest.java
[root@keithpc jar_check1]# java springtest
Hello,spring
[root@keithpc jar_check1]# jar cvf springtest.jar springtest.class
added manifest
adding: springtest.class(in = 426) (out= 286)(deflated 32%)
##Here I run your command after creating the jar file.
[root@keithpc jar_check1]# find . -name "*.jar" -exec jar tf '{}' \|
grep -H "spring" \;
##As you can see, it returns me the class file rather than the
jar file as the output.
springtest.class
grep
like this.find /some/dir -type f -name "*spring*.jar"
spring
jar
files which has the wordspring
in it.