gpt4 book ai didi

linux - 如何从 grep -R 中排除目录?

转载 作者:IT老高 更新时间:2023-10-28 12:14:11 25 4
gpt4 key购买 nike

我要遍历所有子目录,除了“node_modules”目录。

最佳答案

GNU Grep 的最新版本(>= 2.5.2 ) 提供:

--exclude-dir=dir

从递归目录搜索中排除匹配模式 dir 的目录。

所以你可以这样做:

grep -R --exclude-dir=node_modules 'some pattern' /path/to/search

有关语法和用法的更多信息,请参阅

对于较旧的 GNU Greps 和 POSIX Grep ,请按照其他答案中的建议使用 find

或者直接使用 ack (编辑: 或 The Silver Searcher )并完成它!

关于linux - 如何从 grep -R 中排除目录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6565471/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com