我要遍历所有子目录,除了“node_modules”目录。
最佳答案
--exclude-dir=dir
从递归目录搜索中排除匹配模式 dir
的目录。
所以你可以这样做:
grep -R --exclude-dir=node_modules 'some pattern' /path/to/search
有关语法和用法的更多信息,请参阅
- File and Directory Selection 的 GNU 手册页
- 一个相关的 StackOverflow 答案 Use grep --exclude/--include syntax to not grep through certain files
对于较旧的 GNU Greps 和 POSIX Grep ,请按照其他答案中的建议使用 find
。
或者直接使用 ack
(编辑: 或 The Silver Searcher )并完成它!
关于linux - 如何从 grep -R 中排除目录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6565471/