Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

Because I'm lazy.... any time I want to use grep, I want it to be grep -n --colour. Is there a way to permanantly map this?

share|improve this question
2  
+1 for "Because I'm lazy...". Ever considered a career as a developer? :) –  dr Hannibal Lecter Oct 13 '10 at 17:34

3 Answers 3

up vote 27 down vote accepted

In your $HOME/.bashrc file, add:

export GREP_OPTIONS="-n --color"

This will work with egrep too and in aliases that use grep.

share|improve this answer
    
respect. –  myusuf3 Aug 13 '10 at 16:57
3  
Respect but no upvote, eh? ;-) –  richq Aug 13 '10 at 17:08
1  
Aliases can be used after a pipe just fine. They just don't recurse. –  maco Aug 13 '10 at 17:35
1  
Hey hey, I upvoted. I like this better than alias. –  Dmitriy Likhten Aug 13 '10 at 19:37
    
@marco: you're right (with bash) - I was thinking of csh, where they can't. Oops! –  richq Aug 13 '10 at 20:45

Edit ~/.bash_aliases Add a line that says:

alias grep='grep -n --color'

~/.bash_aliases is automatically included by ~/.bashrc if it exists

share|improve this answer
6  
Or add the line in .profile if you want it to work in all shells not just bash. –  Source Lab Aug 13 '10 at 22:16

you can modify the file .bashrc located in your home directory defining an alias, which will override any default setting:

alias grep='grep -n --color'

after the change close and open the terminal again because the file is read only when you open the terminal.

If you take a look on the file .bashrc you will found more default aliases like:

alias ll='ls -l'

alias la='ls -A'

alias l='ls -CF'

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.