grep - grep 如何排除子目录
问题描述
我使用 grep 查找一个字符串,我想用 排除一个目录grep -rl --exclude-dir=application/res --colour 'super'
,但它也在目录下显示匹配application/res/
。
而当我使用时,路径grep -rl --exclude-dir=application --colour 'super'
下没有任何匹配项。application
使用 grep 时如何排除一个子目录。
grep 版本:
$ grep -V
grep (GNU grep) 2.20
grep 帮助:
-r, --recursive like --directories=recurse
-R, --dereference-recursive
likewise, but follow all symlinks
--include=FILE_PATTERN
search only files that match FILE_PATTERN
--exclude=FILE_PATTERN
skip files and directories matching FILE_PATTERN
--exclude-from=FILE skip files matching any file pattern from FILE
--exclude-dir=PATTERN directories that match PATTERN will be skipped.
解决方案
使用 find 您可以排除带有斜杠的整个路径:
find . -path ./application/res -prune -o -type f -exec grep -l super {} +
尽管更便携,但这将比grep -r
. 但就我而言,GNU grep 没有提供排除路径的机制。
推荐阅读
- jquery - 在 jQuery datepicker 上禁用星期一和星期六
- javascript - 我想使用 Highchart 开发蜘蛛网图/雷达图
- angular - TypeScript 编译中缺少 ts。请通过 'files' 或 'include' 属性确保它在您的 tsconfig 中
- javascript - 谷歌地图折线不显示和抛出错误
- google-cloud-platform - Stackdriver Logging API 身份验证问题通过 API Key 机制
- angular - 为什么我的“Angular Material Components”不起作用?
- c - 更改宏值时出现段错误
- wordpress - 单击主页时,用户已注销
- javascript - firebase 云功能模拟器出错
- javascript - Highcharts - 组合和叠加列