background - 将 xargs 生成的命令发送到后台

标签 background xargs unix

我想知道如何将 xargs 生成的命令发送到后台。 例如,考虑

find . -type f  -mtime +7 | tee compressedP.list | xargs compress

我试过了

find . -type f  -mtime +7 | tee compressedP.list | xargs -i{} compress {} &

..出乎意料的是,它似乎将 xargs 发送到后台?

如何使压缩命令的每个实例转到后台?

最佳答案

使用 --max-procs/-P 选项在后台运行 xargs 目标。来自 GNU xargs 版本 4.2.27 的手册页:

--max-procs=max-procs, -P max-procs

Run up to max-procs processes at a time; the default is 1. If max-procs is 0, xargs will run as many processes as possible at a time. Use the -n option with -P; otherwise chances are that only one exec will be done.

(您可能需要将其与 -n 1 结合使用,以确保您要压缩的每个文件都有一个新进程)

关于background - 将 xargs 生成的命令发送到后台,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1952265/

相关文章:

find - 'find' 与 'xargs' 和 'tar'

unix - 如何在 shell 脚本中使用并行执行?

c++ - unix中c++多核CPU使用教程

shell - Bourne Shell 中是否有像 Bash 中那样的进程替换?

c - 如何在后台执行僵尸进程后避免它们

c++ - MFC改变CListCtrl背景颜色

jquery - 由于 -web-kit 效果,Div 没有隐藏

node.js - 是否有令人信服的理由使用基于 AMQP 的服务器而不是 beanstalkd 或 redis?

Linux - Bash - 在许多用户目录中应用 chown

bash - 在 find + xargs grep 中得到退出代码 123