Finding & bashing stuff

We often use the find command to look for specific files like so:

 find . -type f -name '*.rb'

What if you want to do something with the result? With the find command, you can’t pipe the result because it is not a shell and it can’t spawn one.

Luckily find has a -exec function, so that you can do the following:

find . -type f -name '*.txt' -exec bash -c 'cat {}' \;

Note the \; at the end - that’s important if you’re executing the bash shell as it indicates the end of the line.