parallel processing - bash: running script on multiple directories simultaneously -
let's have multiple directories: nmg_1, nmg_2,..., nmg_5
. each of these directories contains 2 subdirectories: fol, unf
. in each of subdirectories there text file.
so, have script: run.sh
, read line of text files in each subdirectory , output file. thus, wondering, there way run script in parallel, is, script run in multiple subdirectories @ once?
given run.sh
required processing on 1 text file @ time, following command keep 4 parallel bash sessions alive:
find -name "*.txt" -print0 | xargs -n 1 -p 4 -0 -i {} bash run.sh {}
from man xargs
:
--max-procs=max-procs, -p max-procs run max-procs processes @ time; default 1. if max-procs 0, xargs run many processes possible @ time. use -n option -p; otherwise chances 1 exec done.
Comments
Post a Comment