You can't nest find -exec
, but you can nest sh
which in turns calls find -exec
. With GNU find, you also have to rewrite the {}
in the inner find so that the outer find won't replace it:
find . -type d -perm 777 \
-exec sh -c 'find "$1" -name "*.php" -exec grep "mail(" {""} \;' _ {} \;
This is the most direct answer to your question. There are multiple ways of simplifying it:
find . -type d -perm 777 \
-exec find {} -name '*.php' -print0 \; | xargs -0 grep -H 'mail('
And an even simpler 90% version would just use grep
to recurse:
find . -type d -perm 777 -exec grep -HR 'mail(' \; | grep '\.php'