Thursday, December 18, 2008

xargs with complicated command line

xargs will pipe to a command. what if it has complex structure?
ls $1 | xargs -I {} -t mv $1/{} $2/{}

here the I command says use {} to replace the piped output

thus we use

find . -iname '*nons*' -print0 |xargs --null -I {} cp {} ../nonstandard-analysis/{}

to deal with
1) spaces in output file names from find we use -print0 and
correspondingly to match we use xargs --null

2) to deal with the xargs applied command which has multiple arguments we use the -I {}
to fill in for the xargs output

cool!