Chris Jefferson Chris Jefferson - 7 months ago 31
Bash Question

Executing a file with one command per line with xargs

I have a file which consists of a series of commands, one per line. For example:

./run_test_1.sh fileA
./run_test_1.sh fileB
./run_test_2.sh fileC


I want to run these in parallel, using xargs.

Answer

Give this a try:

printf "%s\0" "$(cat afile)" | xargs -0 -P 3 -I xxx bash -c xxx

xargs is going to run 3 commands from afile in parallel.

Comments