(NOTE: Replace the string "MY_SEARCH" with your search expression accordingly)
1) Search "MY_SEARCH" in source code (*.cpp, *.h) files:
Code: Select all
$ grep -R "MY_SEARCH" --include *.{cpp,h} source/
-R: Recursive
--include: file pattern / filemask to include (the opposite would be "--exclude")
*.{cpp,h}: pattern to match *.cpp and *.h respectively.
2) Search case-insensitive in "*.php":
Code: Select all
$ grep -Ri "MY_SEARCH" --include *.php source/
-i: case insensitive
3) Show matching lines and their line numbers:
Code: Select all
$ grep -Rin "MY_SEARCH" --include *.php source/
-n: show line numbers of matching lines (next to filename)
4) Show only filenames that contain matches:
Code: Select all
$ grep -Ril "MY_SEARCH" --include *.txt source/
-l: Show only the matching filenames. Not the actual strings/lines.
Might come in handy.
At least they do for me