bash: -exec 在 find 命令和 & [英] bash: -exec in find command and &

查看:23
本文介绍了bash: -exec 在 find 命令和 &的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想跑步:

./my_script.py a_file &

... 在当前文件夹中以 .my_format 结尾的所有文件,所以我这样做:

... on all files in the current folder that end with .my_format, so I do:

find . -type f -name "*.my_format" -exec ./my_script {} & ;

但它不起作用.我应该如何在 -exec 参数中包含 &?

but it doesn't work. How should I include & in the -exec parameter?

推荐答案

试试这个:

$ find . -type f -name "*.my_format" -exec sh -c './my_script {} &' ;

您的尝试失败的最可能原因是 find 使用不理解作业控制的标准 c 库调用的 exec(3) 系列之一执行命令 - & 符号.shell 确实理解在后台运行这个命令",因此 -exec sh ... 调用

The mostly likely reason your attempt didn't work is because find executes the command using one of the exec(3) family of standard c library calls which don't understand job control - the & symbol. The shell does understand the "run this command in the background" hence the -exec sh ... invocation

这篇关于bash: -exec 在 find 命令和 &的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆