Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like to make a utility that always enables the --color argument for the grep command in any distribution. Is there a way to do this or do I have to search for a way for each distribution?

share|improve this question
I'm not aware of any grep.conf file, and --color isn't globally available (maybe on current Linux systems, but probably not on quite a few other "Unix" systems). – Mat Apr 30 '12 at 7:36
up vote 8 down vote accepted

These simple GNU tools don't have config files. You can use shell aliases.

alias grep="grep --color=auto"

Put that in your ~/.bashrc file (or equivalent to what you use). Then you will always use that alias for the grep command.

share|improve this answer
Or better yet, give it a different name like cgrep. If you always invoke grep with --color, it will mess up other commands that read its output. – Keith Thompson Apr 30 '12 at 8:00
That's great, thanks! – f.ardelian Apr 30 '12 at 8:25
@KeithThompson The auto directive tells it to only use color if the output is to a tty. If you pipe it to another program there won't be color codes in the output. – Keith Apr 30 '12 at 8:28

There is no configuration file for grep, but is does listen to environment variables. Check the man grep, search for 'ENVIRONMENT VARIABLES'

These variables can easily be set in your ~/.bashrc or ~/.profile. If you want to make changes global for all users, edit /etc/profile.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.