bash: -exec in find command and &

。_饼干妹妹 提交于 2021-02-18 05:32:11

问题


I want to run:

./my_script.py a_file &

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

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

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


回答1:


Try this:

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

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




回答2:


Try this find command:

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


来源:https://stackoverflow.com/questions/20146676/bash-exec-in-find-command-and

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!