开发者

In Bash, is there a way to "grep -r foobar *" except it is everything except the "log" directory?

开发者 https://www.devze.com 2023-01-20 01:37 出处:网络
the line \\ls -1 | grep -v log | xargs grep -r foobar partially works except it will also skip the \"blog\" directory since it also gets excluded by grep -v log.(the \\ls above i开发者_C百科s to ma

the line

\ls -1 | grep -v log | xargs grep -r foobar

partially works except it will also skip the "blog" directory since it also gets excluded by grep -v log. (the \ls above i开发者_C百科s to make ls not do any alias such as ls -F)


\ls -1 | grep -v ^log$ | xargs grep -r foobar

or

grep --exclude-dir=log -r foobar *


find . -name log -prune -o -type f -print0 |xargs -0 grep foobar


GNU grep has this option:

--exclude-dir=DIR
              Exclude directories matching the pattern DIR from recursive searches.


with bash, you can use extglob

shopt -s extglob
grep "foobar" !(log)
0

精彩评论

暂无评论...
验证码 换一张
取 消