我想知道如何将 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/