ANSI escape sequences

PAINT YOUR BASH

Article from Issue 83/2007
Author(s):

This month, we’ll show you how to decorate your console and give it a fresh new look by adding color to the command line with ANSI escape sequences.

Black on white, or white on black – a terminal doesn’t need to be so boring. Any modern Linux console can display colors to brighten up program output, welcome messages, and even the shell prompt. This article shows you how to add a touch of color and decorate your command line.

The Color Palette

Some programs have their own parameters for adding color to output. Both ls and grep support a --color option that makes command output easier to read (Figure 1). ANSI escape sequences provide the underlying mechanism for this. To get a line of colored output with echo in Bash, you can add an escape sequence to the text (Listing 1).

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Linux Magazine

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

  • Command Line: Bash Prompt

    Color-coding your prompt may help avoid configuration errors and data loss. We’ll show you how to design your own custom shell prompt with color and control sequences.

  • PHP for Sysadmins

    Most admins tend to use the shell, Perl,or Python if they need a system administration script. But there is no need for web programmers to learn another language just to script a routine task. PHP gives admins the power to program command-line tools and even complete web interfaces.

  • Command Line: ls

    The ls command lists files at the command line and gives you many useful details about file properties. With or without colors, this command keeps you on top of your files.

  • Command Line

    A few basic tricks can liven up the command line and add a dash of color to your console.

  • DeskTOPia: hsetroot & Esetroot

    Users who work long hours on a

    desktop computer will appreciate

    something eye-catching to relieve

    the monotony. The hsetroot and

    Esetroot tools offer you more than

    an ordinary desktop.

comments powered by Disqus

Direct Download

Read full article as PDF:

Command_Line_ANSI_Escape_Sequences.pdf (1.04 MB)

News