July 23, 2014
Hot Topics:
RSS RSS feed Download our iPhone app

Linux Console Colors & Other Tricks

  • January 24, 2001
  • By Jay Link
  • Send Email »
  • More Articles »

Available Colors

Now, how do you know which codes do what? The first eight basic EGA colors are defined as follows:
   30    black foreground
   31    red foreground
   32    green foreground
   33    brown foreground
   34    blue foreground
   35    magenta (purple) foreground
   36    cyan (light blue) foreground
   37    gray foreground
So, if I wanted the word "ocean" to appear in light blue, I could type the following:
   echo -e "The \033[36mocean\033[0m is deep."

Combining Commands

Multiple console codes can be issued simultaneously by using a semicolon (";"). One useful command is "1", which sets text to bold. The actual effect is a lighter shade of the chosen color. So, to get a light magenta (purple) as shown in the first example, you would do this:
   echo -e "\033[35;1mCombining console codes\033[0m"
This bolding feature allows you to access the other half of the standard 16 EGA colors. Most notably, brown turns into yellow, and gray turns into bright white. The other six colors are just brighter versions of their base counterparts.

Backgrounds

Text backgrounds can also be set with console codes, allowing you to have white on top of red (for example). Here is the full list of available background options:
   40    black background
   41    red background
   42    green background
   43    brown background
   44    blue background
   45    magenta background
   46    cyan background
   47    white background
What do you think this does?
   echo -e "\033[45;37mGrey on purple.\033[0m"
Finally, here are some other noteworthy command codes:
   0     reset all attributes to their defaults
   1     set bold
   5     set blink
   7     set reverse video
   22    set normal intensity
   25    blink off
   27    reverse video off

Conclusion

And now you have the answer to boring, plain ol' console text. A splash of color can liven up almost any display, creating better aesthetics as well as improving the overall feel.

Unfortunately, these techniques are limited to the console, as they don't display over telnet (unless the remote interface is also a Linux console).

Note that the codes given here are known as ECMA-48 compliant. That is, they work on systems other than Linux. (In case you're interested, ECMA is the European Computer Manufacturers Association, a standards body similar to the ISO). Any system with a VT-102 capable console can use the color codes demonstrated above.

Related Resources

1. ECMA This is the page that covers Standard ECMA-48, "Control Functions for Coded Character Sets".

2. "man console_codes" The console_codes man page contains substantial information on not only ECMA-48 compliant codes, but the Linux-specific ones as well.

3. The Linux Documentation Project The LDP is a vast storehouse of Linux-related knowledge.

About Author

Jay Link is twentysomething and lives in Springfield, Illinois. Aside from Linux, his interests include mountain climbing and flying. He administrates InterLink BBS (an unintentionally not-for-profit Internet provider) in his fleeting spare moments, as well as working various odd jobs to pay the rent.





Page 2 of 2



Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 


Sitemap | Contact Us

Rocket Fuel