Is there any way I could use grep to ignore some files when searching something, something equivalent to svnignore or gitignore? I usually use something like this when searching source code.
grep -r something * | grep -v ignore_file1 | grep -v ignore_file2
Even if I could set up an alias to grep to ignore these files would be good.
What that does is find all files in your current directory excluding the directory (or file) named "ignore", then executes the command grep -r something on each file found in the non-ignored files.
--exclude
option on grep will also work:This searches for perl in files in the current directory excluding files beginning with
try
ortk
.Use shell expansion
You might also want to take a look at ack which, among many other features, by default does not search VCS directories like .svn and .git.
I thinks grep does not have filename filtering. To accomplish what you are trying to do, you can combine find, xargs, and grep commands. My memory is not good, so the example might not work:
Find is flexible, you can use wildcards, ignore case, or use regular expressions. You may want to read manual pages for full description.
after reading next post, apparently grep does have filename filtering.
Here's a minimalistic version of .gitignore. Requires standard utils: awk, sed (because my awk is so lame), egrep:
grepignore
builds a simple alternation clause:not incredibly efficient, but good for manual use