In Unix, how can I produce color, reverse video, and other effects?
In Unix, you can add color and emphasis to documents and programs using
ANSI escape sequences. An escape sequence is the
combination of an escape code (ASCII 27) followed by a left
[), followed by formatting codes,
and finally the letter
m. When displayed by
a communications program that supports ANSI terminal emulation, the
escape sequence will not display, but will instead send a command to
You can use any text editor to add escape sequences. To use Emacs, at the Unix prompt, enter:
filename with the name of the file you want to
edit. To add color or emphasis to a text selection, encapsulate the
selection with escape sequences. To create an escape
sequence in Emacs, press
C-q ESC , then the rest of the
escape sequence. Emacs displays the
ESC code as the string
^[, so, for example, the code for bold text would look like:
To turn off the formatting, at the end of the selection, create an escape sequence with a 0 for the formatting code. So, the escape sequence would look like:
The available codes are:
Normal text, foreground and background
You can combine codes in a single escape sequence by separating them with semicolons. For example, to create a section of text that is bold text with a yellow foreground and blue background, the escape sequence would be:
Therefore, in Emacs, the keystrokes to make the text "Hello, world" bold, with a yellow foreground and blue background, would be:
Once you have finished editing your file, you can view the result by entering, at the Unix prompt:
filename with the name of the file. You
must use the
cat command to display the file because paging programs
more do not properly display escape
Not all communications packages understand these escape sequences. Only ANSI terminals or programs that support ANSI terminal emulation can display a file's formatting. Also, not all applications emulate the ANSI terminal in the same way, and some may do so incompletely, so test any ANSI terminal emulation software for compatibility.
At Indiana University, for personal or departmental Linux or Unix systems support, see At IU, how do I get support for Linux or Unix?
This is document adzf in the Knowledge Base.
Last modified on 2016-11-30 12:58:30.
- Fill out this form to submit your issue to the UITS Support Center.
- Please note that you must be affiliated with Indiana University to receive support.
- All fields are required.