![]() |
Xargs with output of find
Hi guys,
I'm testing some multi-plat java code and I'm getting a bit frustrated with the Linux tests. I need to run the command: Code:
$ java -jar /home/developer/TCO/TabletComicOptimizer.jar <file> <args[]>Normally I would just create a bash script and populate the results of find into an array and then just enumerate the collection but in this specific case I want to demonstrate this operation at the bash terminal. I've tried things like: Code:
~/TCO $ find . -type f -iname "*.cb[rz]" | xargs java -jar TabletComicOptimizer.jar {} 1200x1800 \;How do I execute my java program against each result in the find operation? Thanks! |
Ugh...
-exec is what I actually need: Code:
~/AndriodDev/Comics/Batman - Arkham Reborn $ find . -iname "*.cb[rz]" -exec java -jar ~/Downloads/jComicOptimizer/TabletComicOptimizer.jar "{}" \; |
Hi,
Have you tried not using xargs, but find's -exec operand? Code:
find . -type f -iname "*.cb[rz]" -exec java -jar TabletComicOptimizer.jar {} 1200x1800 \;EDIT: Answer was found while I was typing :) |
Quote:
if using 'find' then -exec is the way to go. If you pipe the output of another program to 'xargs' then this is how you can handle the substitutions explicitly: Code:
... | xargs -I '{}' echo '{} and some other text'So the 'xargs' equivalent 'find -exec' in your initial post would be: Code:
~/TCO $ find . -type f -iname "*.cb[rz]" | xargs -I '{}' java -jar TabletComicOptimizer.jar {} 1200x1800 |
Quote:
Outstanding! |
By the way, you don't need to use '{}' with -I; any character string will do*. I prefer using '@' myself, as it's not a reserved shell character and so doesn't need quoting.
Also remember to use the null separator when working with filenames that can contain spaces. Code:
~/TCO $ find . -type f -iname "*.cb[rz]" -print0 | xargs -I @ -0 java -jar TabletComicOptimizer.jar @ 1200x1800Code:
find . -f -exec foo "{}" \+-- * Using gnu xargs and find, of course. Other implementations may not have the same features. ** Or as many as the command buffer will hold at a time, if the list is large. |
Quote:
Thanks again! |
| All times are GMT -5. The time now is 04:34 PM. |