by termie · 9y ago · 0 comments
for x in $(seq 1 10); do long_process file${x} & done; wait
It doesn't take care of not saturating my cpu or anything; when I need to care about that then I try to remember how to use parallel. for x in ...; do echo long_process file$x ; done | parallel -j 8
EDIT: and in your case, it is even easier with xargs, e.g.: ls files* | xargs -n 1 -P 8 long_process printf "%s\0" files* | xargs -0 -n 1 -P 8 long_process
1. http://mywiki.wooledge.org/ParsingLs find ... -print0|parallel --gnu -X -0 -n 1 your_command "{}" \;
And sometimes the names are so screwed that they have to be renamed first, then this can give you a reasonable new name $(echo $(basename "{}")|tr '[[:blank:]]' '_'| tr -cd '\/.[[:alnum:]]_-' ) seq 10 | parallel long_process file{}
Or simply: parallel long_process ::: file*