There's no rc file for grep, but you can set the environment variable GREP_OPTIONS
to a whitespace-separated list of options that will apply to all grep commands. This requires GNU grep (the implementation on non-embedded Linux, Cygwin and some other systems) 2.4; the --exclude
option is new to GNU grep 2.5. Put something like this in your ~/.profile
:
export GREP_OPTIONS='--color=auto --exclude=*.pyc --exclude-dir=.git'
If you've done this but want to run grep once without those default options, you can override them (e.g. grep --color=never
to force colors off) or empty the GREP_OPTIONS
variable by running GREP_OPTIONS= grep …
.
Another possibility is to define aliases for grep. I use a variant of the following:
alias regrep='grep -Er --exclude=*~ --exclude=*.pyc --exclude-dir=.bzr --exclude-dir=.git --exclude-dir=.svn'