To search for a string called “myFunction” in all text files located in /var/www/html/*.php use:
grep "myFunction" /var/www/html/*.php
|
To search recursively in all sub-directories you would alter the command by adding the -r option:
grep -r "myFunction" /var/www/html
|
Now you have probably noticed that grep prints out the matching lines containing your string, but you may also need the filenames of the files containing the string instead. You can use the -H option to narrow the output the filename followed by the line containing your search string, like so:
grep -H -r "myFunction" /var/www/html
|
This would output something like:
...
your_file.php: line containing myFunction
..
|
To print out just the filename you can cut command like this to clean the output further: (Note the one after the f, not an L)
grep -H -r "myFunction" /var/www/html | cut -d: -f1
|
The new cleaner out put would be like: