1

This question already has an answer here:

This way I get colored output:

grep class testdata.py 

Since this gets set in my .bashrc:

alias grep='grep -n --color'

But if I search like this, I see no colored output:

find -name '*.py'  | xargs grep "class"

Has someone an idea how to enable colored output of grep if called via find ...| xargs grep?

marked as duplicate by don_crissti, Sundeep, Jeff Schaller, Toby Speight, Community Mar 10 '17 at 14:46

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • Because xargs does not know about your aliases. – user218374 Mar 10 '17 at 12:59
0

You have to add --color explicitly because xargs doesn't use your aliases, as mentioned in the comments. So your command would look like:

find -name '*.py'  | xargs grep --color "class"

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