grep
search for string in a dir of files
grep -r '<string>' '<path_to_somewhere>'
Finding all files containing a text string on Linux
grep -rnw '/path/to/somewhere/' -e "pattern"
# `-r` or `-R` is recursive
# `-n` is line numbe
# `-w` stands match the whole word
# `-l` (lower-case L) can be added to just give the file name of matching files.
--exclude
or --include
parameter could be used for greater efficiency:
grep --include=\*.{c,h} -rnw '/path/to/somewhere/' -e "pattern"
--exclude
does the opposite:
grep --exclude=*.o -rnw '/path/to/somewhere/' -e "pattern"
Just like exclude file it's possible to exclude/include directories through --exclude-dir
and --include-dir
parameter; for example, the following shows how to integrate --exclude-dir
:
grep --exclude-dir={dir1,dir2,*.dst} -rnw '/path/to/somewhere/' -e "pattern"