18 ms·
For Java programmers who use Silver Searcher or ack, this lets you search all jars in a directory tree for a given string. Requires GNU Parallel: function
by revscat 12y ago
For Java programmers who use Silver Searcher or ack, this lets you search all jars in a directory tree for a given string. Requires GNU Parallel:
function ffjar() {
jars=(./**/*.jar)
print "Searching ${#jars[*]} jars for '${*}'..."
parallel --no-notice --tag unzip -l ::: ${jars} | ag ${*} | awk '{print $1, ":", $5}'
}
Because it uses parallel it spreads the workload across CPUs. I use this frequently when I have to update/rewrite/create build scripts, and I know a class exists but not which jar file it lives in.
- garblegarble 12y agoThat's pretty neat! I use the following (slower, but short enough that it sticks in my memory so I can do it at a colleague's machine): find . -name "*.jar" | xargs -tn1 unzip -l | grep SomeClass
- burntsushi 12y ago`xargs` also has a `-P` flag which will instruct it to spread work over multiple processes. Given that you already have `-n1`, adding a `-P 0` will have it automatically spread out over all your CPUs.
- garblegarble 12y agoAwesome, that's good to know!
- ole_tange 12y agoBe aware that xargs does not deal nicely with race conditions: (Parallel grep) http://www.gnu.org/software/parallel/man.html#differences_between_xargs_and_gnu_parallel http://www.gnu.org/software/parallel/man.html#differences_be...
- ole_tange 12y agoConsider running 'parallel --bibtex' once.