I want a different color for terminal returns:


$ pwd                //when return key is hit 
$ /home/user/tools   //return value printed in different color, say: grey color

This requirement is not specific to pwd, command but for any command thrown to the terminal, my log will:

  • $black //input
  • $grey //output

hope it is clear.


You generally have to catch the output from the commands and wrap in in echo statements with the color codes preceding the lines. You also need to put the colors back to their "normal" mode once you're done to keep your prompt looking OK. Here's roughly one way to accomplish what you want:

$ echo -e '\e[1;30m'`pwd`; echo -en '\e[0m';

The code \e[1;30m' is gray, the code\e[0m` puts the display back into it's normal mode.

So you could either put this into a script or create an alias that takes the name of a command as an argument and passes it into the echo ... ; echo construct above.


This is a very basic example but just to give you an idea of how this could be implemented, in a Bash shell:

$ c () { echo -e '\e[1;30m'`\$1`; echo -en '\e[0m'; }

This will create a function called c. You can pass it arguments such as pwd:

$ c pwd

You have to use it with discretion though. You can't pass it things such as ls.


The shell actually has nothing to do with colors, it's the terminal (emulator) device that handles them. On linux this is standardized and pretty much all of them (VT's, xterms, etc.) respond to ANSI escape sequences. slm's answer demonstrates their basic usage.

If you want something you can use as a pipe, I have a C utility I wrote for multiplexing output from multiple asynchronous processes backgrounded on one console using different colors, which is handy for debugging inter-related but separate things.


There's a README in the tarball. Basic example:

ls | utf8-colorize -1 3 -b

The ls output will appear in bold yellow. You can set the background as well; aliases may be handy too, eg;

alias green='utf8-colorize -1 2'

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.