Ingoring .svn files with grep

If you're using a software respository like Subversion and you're having hassle with your repo files turning up in your Grep searches then there are a couple of things you can do to tidy this up.

Searching with the -v option removes that pattern from the search. So something like this will exclude all the .svn files from your grep search results:

grep -r mystring mypath | grep -v .svn

or using the --exclude option as is says in the grep man page.

"
--exclude=GLOB
Skip files whose base name matches GLOB (using wildcard matching). A file-name glob can use *, ?, and [...] as wildcards, and \ to quote a wildcard or backslash character literally.
"


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

But an edit to your .bashrc file like this will exclude .svn from grep searches them forever!

Just open your .bashrc file and stick this at the top:

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




Yeh

Noice!

Post new comment

  • 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>
  • Lines and paragraphs break automatically.

More information about formatting options