php - *nix: Performing nested -exec with find command -
i'm trying following thing: hunt down 777 directories, , within directories, hunt down php files contain string "mail(". goal make part of cron-job runs every night , finds of php files contain mail functions may have been inserted surreptitiously onto our server. so, i've written command:
find -type d -perm 777 -exec find {} -name "*.php" \; -exec grep "mail(" {} \;
which (is supposed to):
1: find folders 777 privileges
2: each such folder, find php files contained therein
3: each such file, perform grep find string "mail("
however, doesn't appear working. doing giving me list of php files in 777-privileged directories, it's not performing grep. i've looked @ postings this:
which lead me believe nesting of -exec possible. there obvious i'm missing? in advance time!
you can't nest find -exec
, can nest sh
in turns calls find -exec
. gnu find, have rewrite {}
in inner find outer find won't replace it:
find . -type d -perm 777 \ -exec sh -c 'find "$1" -name "*.php" -exec grep "mail(" {""} \;' _ {} \;
this direct answer question. there multiple ways of simplifying it:
find . -type d -perm 777 \ -exec find {} -name '*.php' -print0 \; | xargs -0 grep -h 'mail('
and simpler 90% version use grep
recurse:
find . -type d -perm 777 -exec grep -hr 'mail(' \; | grep '\.php'
Comments
Post a Comment