Replace grep command with grep -n --colour?
In your $HOME/.bashrc file, add:
export GREP_OPTIONS="-n --color"
This will work with egrep
too and in aliases that use grep.
Update: GREP_OPTIONS is deprecated from grep 2.21 on and if you use this solution you will see the following warning:
grep: warning: GREP_OPTIONS is deprecated; please use an alias or script
The best solution is to therefore follow maco's advice in his answer. Or switch to using ag, which outputs in color by default.
Edit ~/.bash_aliases Add a line that says:
alias grep='grep -n --color'
~/.bash_aliases is automatically included by ~/.bashrc if it exists
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'