If you want to see the full paths, I would recommend to cd
to the top directory (of your drive if using windows)
cd C:\
grep -r somethingtosearch C:\Users\Ozzesh\temp
Or on Linux:
cd /
grep -r somethingtosearch ~/temp
if you really resist on your file name filtering (*.log) AND you want recursive
(files are not all in the same directory), combining find
and grep
is the most flexible way:
cd /
find ~/temp -iname '*.log' -type f -exec grep somethingtosearch '{}' \;
For me
grep -b "searchsomething" *.log
worked as I wanted
The easiest way to print full paths is replace relative start path with absolute path:
grep -r --include="*.sh" "pattern" ${PWD}
I fall here when I was looking exactly for the same problem and maybe it can help other.
I think the real solution is:
cat *.log | grep -H somethingtosearch
Use:
grep somethingtosearch *.log
and the filenames will be printed out along with the matches.
Command:
grep -rl --include="*.js" "searchString" ${PWD}
Returned output:
/root/test/bas.js
Source: Stackoverflow.com