Bash: -exec on find and &

I want to run:

./my_script.py a_file & 

... for all files in the current folder ending with .my_format , so I:

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

but that will not work. How to include & in the -exec parameter?

+6
source share
2 answers

Try the following:

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

The most likely reason why your attempt does not work is because find executes a command using one of the standard standard library calls with t21, which do not understand job control - the & symbol. The shell really understands "run this command in the background", therefore, calling -exec sh ...

+8
source

Try this find command:

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

Source: https://habr.com/ru/post/958639/


All Articles