Posts Tagged ‘grep’

Ignore SVN directories in GREP searches

Monday, June 16th, 2008

SVN hidden directories cache a lot of temporary files. Most of the time when you do a recursive GREP you don’t need to go through them.

You can avoid exploring those sub-directories either manually every time you grep:

grep -r --exclude=\*.svn\*

Or set the GREP_OPTIONS environment variable, either in your .bashrc or by exporting it in your command line like so:

GREP_OPTIONS="--exclude=\*.svn\*"
export GREP_OPTIONS

Adding this command to .bashrc will make it permanent, even next time you log in again.

The more recent versions of grep (from 2.5.3) have an exclude-dir option:

export GREP_OPTIONS="--exclude-dir=.svn"

Older versions of grep that don’t support the exclude-dir options will return this error:

bash#  grep -R "boo" .
grep: unrecognized option `--exclude-dir=.svn'
Usage: grep [OPTION]... PATTERN [FILE]...
Try `grep --help' for more information.
bash#
bash# grep -V
grep (GNU grep) 2.5.1

Copyright 1988, 1992-1999, 2000, 2001 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

bash#

Source