I use the following code to search for PHP scripts containing the specified text. (Thanks, woolmilkporc.)
find /opt /home \( -name "*.php" -o -name "*.php[3-6]" -o -name "*.inc" \) | xargs grep -Eil "mysql|select|result" 2>/dumpErrors.txt>dumpfile.txt
There are two problems.
1. "Permission denied" errors are not being logged to "dumpfile.txt".
2. Some files are generating grep errors because of the file name. For example, this file:
/home/mydir/Copy of myscript.php
Causes this error:
grep: /home/mydir/Copy: No such file or directory