美文网首页
grep 排除指定目录,多个工程中查找字符

grep 排除指定目录,多个工程中查找字符

作者: McDu | 来源:发表于2020-09-16 17:57 被阅读0次

在当前目录下的多个工程中查找指定字符串,排除 node_modules dir2 等指定目录。

下面是三种可以实现的方法:

  1. 结合 find 命令和 grep 命令 -exec
    find . \( -name node_modules -prune \) -o \( -name dir2 -prune \) -o -name "*.js" -exec grep --color -Hn "xxxx" {} 2>/dev/null \;

  2. 使用 grep 命令的 --exclude-dir 参数 (此方法特别慢)
    grep -R --exclude-dir={node_modules,dir2} 'xxxx' .
    注意:--exclude-dir={dir1,dir2} dir 中间不能有空格。

  3. Ag:the_silver_searcher
    优点:快,自动将 .gitignore 里的文件忽略


https://stackoverflow.com/questions/6565471/how-can-i-exclude-directories-from-grep-r

相关文章

网友评论

      本文标题:grep 排除指定目录,多个工程中查找字符

      本文链接:https://www.haomeiwen.com/subject/ssjhyktx.html