You can use:
grep -r "string to be searched" /path/to/dir
The r
stands for recursive and so will search in the path specified and also its sub-directories. This will tell you the file name as well as print out the line in the file where the string appears.
Or a command similar to the one you are trying (example: ) for searching in all javascript files (*.js):
find . -name '*.js' -exec grep -i 'string to search for' {} \; -print
This will print the lines in the files where the text appears, but it does not print the file name.
In addition to this command, we can write this too:
grep -rn "String to search" /path/to/directory/or/file
-r: recursive search
n: line number will be shown for matches