bash: -exec in find command and &

后端 未结 2 2007
栀梦
栀梦 2021-02-14 20:16

I want to run:

./my_script.py a_file &

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



        
2条回答
  •  感动是毒
    2021-02-14 20:58

    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

提交回复
热议问题