Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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
1  
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

2 Answers 2

up vote 7 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
2  
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
4  
@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

 
discard

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.