Do the following:
grep -rnw '/path/to/somewhere/' -e "pattern"
-ror-Ris recursive,-nis line number, and-wstands match the whole word.-l(lower-case L) can be added to just give the file name of matching files.- Along with these,
--excludeor--includeparameter could be used for efficient searching. Something like below:
grep --include=\*.{c,h} -rnw '/path/to/somewhere/' -e "pattern"
This will only search through the files which have .c or .h extensions. Similarly a sample use of --exclude:
grep --exclude=*.o -rnw '/path/to/somewhere/' -e "pattern"
Above will exclude searching all the files ending with .o extension. 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"
This works very well for me, to achieve almost the same purpose like yours.
For more options :
man grep
本文介绍如何使用grep命令进行高效地文件搜索。包括递归搜索目录、显示匹配行的行号、精确匹配整个单词以及排除特定文件或目录等功能。通过这些选项的组合使用,可以大大提高搜索效率。
2253

被折叠的 条评论
为什么被折叠?



