我试图实现并行查找以减少大FS遍历时间:
find $1 -mindepth 2 -maxdepth 2 -type d | xargs -P5 -n1 find
效果很好,但是五个(-P5)“查找”进程并行运行,弄乱了它们的输出,因此字符串有时会破裂。如何摆脱这种行为? 应该是 xargs 的常见问题,但似乎没有人使用它的并行功能。
最佳答案
您可以使用写入单独的文件
find $1 -mindepth 2 -maxdepth 2 -type d -print0 | xargs -0 -P5 -n1 -I{} sh -c 'find "{}" > "/tmp/{}.dirlist.txt"'
最后将它们放在一起
。
关于shell - xargs -P 困惑标准输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27206358/