Unix: find, xargs, zipinfo and the 'caution: filename not matched:' error
As I mentioned in my previous post last week I needed to scan all the jar files included with the neo4j-enterprise gem and I started out by finding out where it’s located on my machine:
$ bundle show neo4j-enterprise
/Users/markhneedham/.rbenv/versions/jruby-1.7.1/lib/ruby/gems/shared/gems/neo4j-enterprise-1.8.2-java
I then thought I could get a list of all the jar files using http://unixhelp.ed.ac.uk/CGI/man-cgi?find and pipe it into http://linux.about.com/library/cmd/blcmdl1_zipinfo.htm via xargs to get all the file names and then search for HighlyAvailableGraphDatabaseFactory:
Unfortunately when I tried that it didn’t quite work:
$ cd /Users/markhneedham/.rbenv/versions/jruby-1.7.1/lib/ruby/gems/shared/gems/neo4j-enterprise-1.8.2-java/lib/neo4j-enterprise/jars/
$ find . -iname "*.jar" | xargs zipinfo
caution: filename not matched: ./lib/neo4j-enterprise/jars/logback-classic-0.9.30.jar
caution: filename not matched: ./lib/neo4j-enterprise/jars/logback-core-0.9.30.jar
caution: filename not matched: ./lib/neo4j-enterprise/jars/neo4j-backup-1.8.2.jar
caution: filename not matched: ./lib/neo4j-enterprise/jars/neo4j-com-1.8.2.jar
caution: filename not matched: ./lib/neo4j-enterprise/jars/neo4j-consistency-check-1.8.2.jar
caution: filename not matched: ./lib/neo4j-enterprise/jars/neo4j-ha-1.8.2.jar
caution: filename not matched: ./lib/neo4j-enterprise/jars/neo4j-udc-1.8.2.jar
caution: filename not matched: ./lib/neo4j-enterprise/jars/org.apache.servicemix.bundles.netty-3.2.5.Final_1.jar
caution: filename not matched: ./lib/neo4j-enterprise/jars/server-api-1.8.2.jar
caution: filename not matched: ./lib/neo4j-enterprise/jars/slf4j-api-1.6.2.jar
caution: filename not matched: ./lib/neo4j-enterprise/jars/zookeeper-3.3.2.jar
I switched 'zipinfo' to 'echo' to see what was going on which resulted in the following output:
$ find . -iname "*.jar" | xargs echo
./log4j-1.2.16.jar ./logback-classic-0.9.30.jar ./logback-core-0.9.30.jar ./neo4j-backup-1.8.2.jar ./neo4j-com-1.8.2.jar ./neo4j-consistency-check-1.8.2.jar ./neo4j-ha-1.8.2.jar ./neo4j-udc-1.8.2.jar ./org.apache.servicemix.bundles.netty-3.2.5.Final_1.jar ./server-api-1.8.2.jar ./slf4j-api-1.6.2.jar ./zookeeper-3.3.2.jar
As I understand it, xargs expects arguments to be separated by a space and I thought it would apply the command to each argument individually but it seemed to be including the space as part of the file name.
I’ve previously used the '-n' flag to xargs to explicitly tell it to call the corresponding command with one argument at a time and that seemed to do the trick:
$ find . -iname "*.jar" | xargs -n1 zipinfo
Archive: ./log4j-1.2.16.jar 481535 bytes 346 files
-rw---- 2.0 fat 3186 bX defN 30-Mar-10 23:25 META-INF/MANIFEST.MF
-rw---- 2.0 fat 0 bl defN 30-Mar-10 23:25 META-INF/
-rw---- 2.0 fat 11366 bl defN 30-Mar-10 23:14 META-INF/LICENSE
-rw---- 2.0 fat 160 bl defN 30-Mar-10 23:14 META-INF/NOTICE
-rw---- 2.0 fat 0 bl defN 30-Mar-10 23:25 META-INF/maven/
-rw---- 2.0 fat 0 bl defN 30-Mar-10 23:25 META-INF/maven/log4j/
...
Of course to solve this particular we don’t actually need to use find and xargs since we can just call zipinfo with the wildcard match:
$ zipinfo \*.jar
Archive: log4j-1.2.16.jar 481535 bytes 346 files
-rw---- 2.0 fat 3186 bX defN 30-Mar-10 23:25 META-INF/MANIFEST.MF
-rw---- 2.0 fat 0 bl defN 30-Mar-10 23:25 META-INF/
-rw---- 2.0 fat 11366 bl defN 30-Mar-10 23:14 META-INF/LICENSE
-rw---- 2.0 fat 160 bl defN 30-Mar-10 23:14 META-INF/NOTICE
-rw---- 2.0 fat 0 bl defN 30-Mar-10 23:25 META-INF/maven/
-rw---- 2.0 fat 0 bl defN 30-Mar-10 23:25 META-INF/maven/log4j/
-rw----
...
I’m curious why xargs didn’t work as I expected it to though - have I just misremembered its default behaviour or is something weird going on?
About the author
I'm currently working on short form content at ClickHouse. I publish short 5 minute videos showing how to solve data problems on YouTube @LearnDataWithMark. I previously worked on graph analytics at Neo4j, where I also co-authored the O'Reilly Graph Algorithms Book with Amy Hodler.