使用来自 cat 的输入进行多线程 xargs
我的服务器上有一个文本文件files.txt
,每一行都是一个具有完整路径的文件,例如/home/lelouch/dir/randomfile.txt
。
我想循环遍历 files.txt,并将每个文件名传递给另一个脚本。
我已经让它像这样工作了:
cat /home/lelouch/dir/files.txt | xargs -0 -n 1 -P 30 /home/lelouch/bin/script.
问题是,虽然我想一次处理 30 个文件,但它一次只发生 1 个。我尝试了其他一些方法,但还没有达到我想要的效果。
有什么想法吗?
I have a text file files.txt
on my server, on each line is a file with the full path, e.g. /home/lelouch/dir/randomfile.txt
.
I want to loop through files.txt, and pass each filename to another script.
I have gotten this to work like this:
cat /home/lelouch/dir/files.txt | xargs -0 -n 1 -P 30 /home/lelouch/bin/script.
The problem is, although I want to process it 30 files at a time, it's only happening 1 at a time. I've tried a few other ways, but I haven't gotten it to work like I want.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您说每行行都是一个文件路径,但您使用
xargs
的-0
选项,它将分隔符从换行符切换为空特点。从man
页面:不要使用 <代码>-0选项:
You say that each line is a filepath, but you use the
-0
option ofxargs
, which switches the separator from a newline to a null character. From theman
page:Don't use the
-0
option:我想你想要GNU Parallel。
I think you want GNU Parallel.
--max-args
是您需要的正确选项--max-args
is the right option you need