Handy command on Linux/Mac to find all files matching a pattern containing a specific text. This will also print file name.
$ find . -type f -name "*.php" -exec grep -H foo {} \; ./dir1/file1.php:function foo () { ./dir1/file2.php:foo();
Few points to note
grep -H
causes the command to print file name-type f
will only run the command (specified by-exec
) on files{}
gets filled with file name.- Backslash before semicolon (\;) is used to protect it from shell interpretation.