xargs -P messes stdout

251 Views Asked by At

I trying to achieve parallel find to reduce big FS traversing time:

find $1 -mindepth 2 -maxdepth 2 -type d | xargs -P5 -n1 find

works good but five (-P5) "find" processes run in parallel mess their output so strings break apart sometimes. How to rid off this behavior? Should be а usual problem with xargs but seems nobody uses its parallel feature.

1

There are 1 best solutions below

0
On

You can write to separate files using

find $1 -mindepth 2 -maxdepth 2 -type d -print0 | xargs -0 -P5 -n1 -I{} sh -c 'find "{}" > "/tmp/{}.dirlist.txt"'

And then cating them together at the end.