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)
精彩评论