How to show grep result with complete path or file name
Assuming you have two log-files in:
- C:/temp/my.log
- C:/temp/alsoMy.log
cd to C: and use:
grep -r somethingtosearch temp/*.log
It will give you a list like:
temp/my.log:somethingtosearch
temp/alsoMy.log:somethingtosearch1
temp/alsoMy.log:somethingtosearch2
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
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 '{}' \;