Parallelize bash processes with xargs

Posted by Moser on 12 May 2015

Just a quick one:

xargs can help you to start multiple processes simultaneously:

$ time echo $'1\n2' | xargs -n 1 sleep                       

real    0m3.007s
user    0m0.001s
sys     0m0.007s
$ time echo $'1\n2' | xargs -P 2 -n 1 sleep                  

real    0m2.007s
user    0m0.001s
sys     0m0.006s

With -P N or --max-procs=N xargs will start up to N processes at the same time.