将 xargs 生成的命令发送到后台
我想知道如何将 xargs 生成的命令发送到后台。 例如,考虑到
find . -type f -mtime +7 | tee compressedP.list | xargs compress
我尝试过
find . -type f -mtime +7 | tee compressedP.list | xargs -i{} compress {} &
..并且出乎意料的是,它似乎将 xargs 发送到后台?
如何使 compress 命令的每个实例转到后台?
I want to know how I can send the command(s) spawned by xargs to background.
For example, consider
find . -type f -mtime +7 | tee compressedP.list | xargs compress
I tried
find . -type f -mtime +7 | tee compressedP.list | xargs -i{} compress {} &
.. and as unexpected, it seems to send xargs to the background instead?
How do I make each instance of the compress command go to the background?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
使用
--max-procs
/-P
选项在后台运行 xargs 目标。来自 GNU xargs 版本 4.2.27 的手册页:(您可能需要将其与
-n 1
结合使用,以确保您要压缩的每个文件都有一个新进程)Use the
--max-procs
/-P
option to run xargs targets in the background. From the man page of GNU xargs version 4.2.27:(You may want to combine this with
-n 1
to makes sure that there is a new process for each file you want to compress)您可能可以编写一个非常快速的 shell 脚本来调用 compress。
那么
尽管我认为使用这个 xargs 参数你可能会更高兴:
这个命令应该一次查找 / tee / 压缩 10 个文件直到完成,并立即将控制权返回给调用脚本/shell。
You could probably make a very quick shellscript to call compress.
then
Although I think you might be happier using this xargs argument:
This command should find / tee / compress 10 files at a time until its done, as well as returning control immediately to the calling script/shell.
对于 SunOS,您可以查看 GNU Parallel http://www.gnu.org/software/parallel /
它还有一个额外的好处,即如果文件名包含“”或空格,则不会错误地终止。添加 -j+0 将使每个 CPU 核心运行一次压缩。
For SunOS you may have a look at GNU Parallel http://www.gnu.org/software/parallel/
It has the added benefit of not terminating incorrectly if the filename contains ' " or space. Adding -j+0 will make it run one compress per CPU core.
当我想编辑包含 foo
grep -rl foo ./ | 的所有文件时,这对我有用。 `xargs emacs` &
This works for me when I want to edit all files that contain foo
grep -rl foo ./ | `xargs emacs` &
在 SunOS/Solaris 上,将命令包装在对 sh(或其他 shell)的调用中:
这应该并行运行压缩,而无需其他工具。
On SunOS/Solaris, wrap the command in a call to sh (or other shell):
This should run the compresses in parallel without additional tools.