How to ignore .svn
directories in grep
?
This has bothered me for a while. A google search shows two popular implementations to work around this: using grep
's --exclude
parameter or use find
to filter out the hidden directories. I chose the --exclude
parameter approach since it is pretty neat and easy to integrate into my own bash environment by defining an alias.
Here is the alias definition in my ~/.bash_profile
alias g="egrep --exclude=\*.svn\* -r -n "
9 comments:
Thanks for the post; after typing "| grep -v svn" for the 100th time this is just what I needed.
I couldn't get your script to ignore DIRECTORIES. I came up with a bash function and instructions on how to install here. Let me know what you think.
Thanks for this neat little trick!
amazing! thanks !
Thanks!
very helpful
exclude works on file name only. you need exclude-dir
also, grep does all you need and is more available.
alias g='grep --color=always -n --exclude-dir=\*.svn\*'
Thanks!
Greping through .svn directories takes more time and makes finding results difficult.
Before your tip, I was using a piped "grep -v .svn" but it wastes time and removes terminal colors because of the pipe.
You can also set the GREP_OPTIONS in your .bashrc, details here:
http://blog.bottomlessinc.com/2008/06/ignore-svn-directories-in-grep-searches/
I prefer setting GREP_OPTIONS="--exclude-dir=.svn" in ~/.bashrc
Post a Comment