Tell me more ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

How do I customize bash colors for command output?

For example; I run ls and want directories and files to be a different color. How do I accomplish this? I see that distro's are doing this but I cannot find any documentation on colorizing OUTPUT from other commands.

share|improve this question
Although this is not what I was looking for, using VI(m) as a root always had no colors; I have found this to enable coloring of VI(m) (incase someone else comes to this question and wants to fix VI(m) coloring) kb.mediatemple.net/questions/1565/Enabling+vi+syntax+colors#gs – J Moore Jul 1 '12 at 23:32

2 Answers

up vote 6 down vote accepted

That's not something your shell does. Color is generated through special control characters. Your terminal emulator needs to translate them into actual color.

For ls, you need to set

  • LSCOLORS (FreeBSD, OS X, ..) or
  • LS_COLORS (Linux).

See here for an LS_COLORS generator. You can then call

  • ls --color (Linux)
  • ls -G or set the CLICOLOR environment variable (BSD variants).

The rest is up to your terminal emulator. For example, my iTerm2 is configured like this:

share|improve this answer
How do I find out which commands support colorized output? – J Moore Jun 13 '12 at 2:15
You really can't. Most builtin commands won't colorize output unless explicitly called (like in ls). Most newer command-line tools have some sort of colorization, but it really depends. You can't find that out by just looking at the program. See uzsolt's answer below for a wrapper that would colorize anything. – slhck Jun 13 '12 at 7:56

Maybe you can check a wrapper, eg. cw:

cw is a non-intrusive real-time ANSI color wrapper for common unix-based commands on GNU/linux. cw is designed to simulate the environment of the commands being executed, so that if a person types 'du', 'df', 'ping', etc. in their shell it will automatically color the output in real-time according to a definition file containing the color format desired. cw has support for wildcard match coloring, tokenized coloring, headers/footers, case scenario coloring, command line dependent definition coloring, and includes over 50 pre-made definition files.

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.