One of the most beautiful things about bash is that you can actually create any number of subshells and make them run in parallel. I needed to perform a very large find (believe me, it is huge, it’s huge goey) that would take “billions and billions” of years to finish. Thanks to subshells it finished way quicker.
The code inside ( ) will be executed in a subshell, if you put a & after that, it will run in the background. A ‘wait’ should be placed before the end to wait for the background processes to finish.
Code goes as follows:
#!/bin/bash for i in `ls | grep folder_regex` do # One process per folder ( [ -d "$i/subfolder" ] || continue echo "Searching in $i/subfolder" find ./$i/subfolder/ -iname "regex" >> ~/results/$i"_results.lst" ) & done wait