使用来自 cat 的输入进行多线程 xargs

发布于 2025-01-07 00:02:39 字数 358 浏览 2 评论 0原文

我的服务器上有一个文本文件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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

过度放纵 2025-01-14 00:02:39

您说每行都是一个文件路径,但您使用xargs-0选项,它将分隔符从换行符切换为空特点。从 man 页面:

输入项由空字符而不是空格终止,并且引号和反斜杠并不特殊(每个字符均按字面意思理解)....

不要使用 <代码>-0选项:

cat /home/lelouch/dir/files.txt | xargs -P 30 -n 1 /home/lelouch/bin/script

You say that each line is a filepath, but you use the -0 option of xargs, which switches the separator from a newline to a null character. From the man page:

Input items are terminated by a null character instead of by whitespace, and the quotes and backslash are not special (every character is taken literally)....

Don't use the -0 option:

cat /home/lelouch/dir/files.txt | xargs -P 30 -n 1 /home/lelouch/bin/script
ㄖ落Θ余辉 2025-01-14 00:02:39

我想你想要GNU Parallel

I think you want GNU Parallel.

久隐师 2025-01-14 00:02:39

--max-args 是您需要的正确选项

cat /home/lelouch/dir/files.txt | xargs --max-args=30 /home/lelouch/bin/script

--max-args is the right option you need

cat /home/lelouch/dir/files.txt | xargs --max-args=30 /home/lelouch/bin/script
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文