开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜