Linux查找某个目录下包含某个字段的文件

1.查找当前目录中所有含某一字段的文件(包含文件夹)

1
find . | xargs grep "custom"

2.查找当前目录中所有含某一字段的文件(不包含文件夹),只查看文件

1
find . -type f | xargs grep "custom'

3.列出文件名, 不需要查看内容呢。grep 提供了-l来只显示文件名称

1
find . -type f | xargs grep "custom' -l

###4.滤掉某些文件夹,不去这些文件夹下查看呢, 使用-purn。例如不看.git文件下的文件
(具体使用方法查看:https://blog.csdn.net/u011517841/article/details/53204524

1
find . -path ./.git -prune -o -type f | xargs grep "custom" -l

###5. 当然查看某个目录下含有某个字段也可以直接使用grep

1
grep -r "custom" -l