sh 搜索文件以查找特定内容

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sh 搜索文件以查找特定内容相关的知识,希望对你有一定的参考价值。

Do the following:

grep -rnw '/path/to/somewhere/' -e "pattern"

grep --exclude=\*.{o,a,.so} -rnw '.' -e "msse"

-r or -R is recursive, -n is line number and -w stands match the whole word. -l (letter L) can be added to have just the file name.

Along with these, --exclude or --include parameter 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, the following shows how to integrate --exclude-dir:

grep --exclude-dir={dir1,dir2,*.dst} -rnw '/path/to/somewhere/' -e "pattern"
This works for me very well, to achieve almost the same purpose like yours.

以上是关于sh 搜索文件以查找特定内容的主要内容,如果未能解决你的问题,请参考以下文章

sh 查找特定文件,并加以拷贝

CMD 搜索目录以在文件中查找字符串

如何使用 postgres/nodejs 在表中查找特定内容

grep 递归查找 Linux 上的特定文件类型

linux 上查找包含特定文本的所有文件

我可以搜索现有 IAM 策略以查找特定操作吗?