Skip to main content
2 of 2
added quotes around `$0` to prevent issues with directory names that contain whitespace

To run find on its own result, you can use the -c argument to sh (or bash) to prevent the outer find command from treating the inner {} specially. However, you then need to pass the result from the outer find as an argument to sh, which can be expanded with $0:

find . -type d -name "*.data" \
      -exec sh -c 'find "$0" -type f -name "*.important.txt" -exec echo \{\} \;' \{\} \;

Note: $0 should be quoted ("$0") to prevent issues with directory names containing whitespace.

This is not really a "recursive" solution, because it doesn't allow arbitrarily deep nesting without some hairy escaping, but it does support the two levels of find -execs you asked for in your example.

If your example is similar to your actual problem, you might also experiment with the -path argument to find instead:

find . -path '*.data/*important.txt'