I have defined grep as

alias grep="grep --colour -iTHn"

So, the output is:

<filename>  <lineno>  <line with matching word>

Now, with my dark terminal, the filename color is almost unreadable. I can do

export GREP_COLORS='fn=00;32'

to change my filename, or

export GREP_COLOR='00;35'

to change my matched word, but I have failed to do them together.

So, the question is, is it possible to highlight all the field of my grep output with custom value/ colour? Say, 01;34 to filename, 01;32 to linenumber and 01;35 to keyword?


The specifiers in GREP_COLORS are colon-delimited, so you can do what you're asking with this line:

GREP_COLORS='fn=01;34:ln=01;32:mt=01;35' grep --colour -iTHn <pattern> <file>

The details are of course in the manual here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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