User login

Grep multiple files but exclude .svn (subversion) directories

The --exclude flag described below does not work.

This does:

grep -nHR 'needle' . | grep -v svn
from http://episteme.arstechnica.com/eve/forums/a/tpc/f/6330927813/m/902005657831

grep exclude .svn

Setting $GREP_OPTIONS in ~/.bashrc like this did the trick
export GREP_OPTIONS="--exclude="\*/.svn/\*"

At 11:41 AM -0400 4/11/04, Stephen Peters wrote:
>Brad Cox writes:
>
>> #1 on the wish list: what is the svn-friendly way to use grep -r foo
>> src to find all the foos in my working src directory, without
>> interference from hits in svn's administrative area (.svn). Hopefully
>> a global setting somewhere so I don't have to type special commands
>> each time. There are hopeful prospects in the man pages but I've not
>> yet hit on a working combination.
>
>I've made use of
> alias rg='grep --exclude=\*.svn\* -r'
>
>And then was able to type
> rg foo src

[forgot URL]

http://snippets.dzone.com/posts/show/3707

grep -r PATTERN * | grep -v '/.svn/'

More grep:

http://www.ss64.com/bash/grep.html
http://www.computerhope.com/unix/uegrep.htm

The --exclude flag described below does not work.

This does:

grep -nHR 'needle' . | grep -v svn
from http://episteme.arstechnica.com/eve/forums/a/tpc/f/6330927813/m/902005657831

grep exclude .svn

Setting $GREP_OPTIONS in ~/.bashrc like this did the trick
export GREP_OPTIONS="--exclude="\*/.svn/\*"

At 11:41 AM -0400 4/11/04, Stephen Peters wrote:
>Brad Cox writes:
>
>> #1 on the wish list: what is the svn-friendly way to use grep -r foo
>> src to find all the foos in my working src directory, without
>> interference from hits in svn's administrative area (.svn). Hopefully
>> a global setting somewhere so I don't have to type special commands
>> each time. There are hopeful prospects in the man pages but I've not
>> yet hit on a working combination.
>
>I've made use of
> alias rg='grep --exclude=\*.svn\* -r'
>
>And then was able to type
> rg foo src

[forgot URL]

http://snippets.dzone.com/posts/show/3707

grep -r PATTERN * | grep -v '/.svn/'

More grep:

http://www.ss64.com/bash/grep.html
http://www.computerhope.com/unix/uegrep.htm

Comments

--exclude-dir works (since grep 2.5)

Grep 2.5 have a new option item --exclude-dir, it should work for you.

grep --exclude-dir=*/.svn/* --exclude=*~ pattern path/to/search/ -Rn

should work for you.

or set it in bash.rc

export GREP_OPTIONS="--exclude-dir=\*/.svn/\* --exclude=\*~"

check my blog :

http://bmmkevin.blogspot.com/

Post new comment

The content of this field is kept private and will not be shown publicly.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • You can use Markdown syntax to format and style the text. Also see Markdown Extra for tables, footnotes, and more.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img> <blockquote> <small> <h2> <h3> <h4> <h5> <h6> <sub> <sup> <p> <br> <strike> <table> <tr> <td> <thead> <th> <tbody> <tt> <output>
  • Lines and paragraphs break automatically.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.