1、维基百科（译者怕翻译偏差大，保留原文）
In computing, ANSI escape code (or escape sequences) is the method of in-band signaling to control formatting, color, and other output options on video text terminals.

To encode this formatting information, it embeds certain sequences of bytes into the text, which have to be interpreted specially, not as codes of characters.

Although hardware text terminals have become increasingly rare in the 21st century, the relevance of this standard persists because most terminal emulators interpret at least some of the ANSI escape sequences in the output text.

One notable exception is the win32 console component of Microsoft Windows.

2、微软的解释

Sequence elements

Escape sequences start with the character ESC (ASCII decimal 27/hex 0x1B/octal 033).

For two character sequences, the second character is in the range ASCII 64 to 95 (@ to _).

However, most of the sequences are more than two characters, and start with the characters ESC and [ (left bracket).

This sequence is called CSI for Control Sequence Introducer (or Control Sequence Initiator). The final character of these sequences is in the range ASCII 64 to 126 (@ to ~).

There is a single-character CSI (155/0x9B/0233) as well.

The ESC+[ two-character sequence is more often used than the single-character alternative, for details see C0 and C1 control codes.
ESC[，这两个字符序列比单个字符形式用的更多，细节参看C0和C1控制编码。
Only the two-character sequence is recognized by devices that support just ASCII (7-bit bytes) or devices that support 8-bit bytes but use the 0x80–0x9F control character range for other purposes.

On terminals that use UTF-8 encoding, both forms take 2 bytes (CSI in UTF-8 is 0xC2, 0x9B) but the ESC+[ sequence is clearer.

Though some encodings use multiple bytes per character, the following discussion is restricted to ASCII characters, and so assumes each character is directly represented by a single byte.

30–37    Set text color (foreground)    30 + x, where x is from the color table below
38    Set xterm-256 text color (foreground)[dubious – discuss]    next arguments are 5;x where x is color index (0..255)
39    Default text color (foreground)    implementation defined (according to standard)
40–47    Set background color    40 + x, where x is from the color table below
48    Set xterm-256 background color    next arguments are 5;x where x is color index (0..255)
49    Default background color    implementation defined (according to standard)

Colors
Text colors (and SGR parameters in general) are manipulated using CSI n1 [;n2 [; ...]] m sequences, where each n1, n2, ... is an SGR parameter as shown above.

Thus, for instance, you use codes 30+i to specify foreground color, 40+i to specify background color, where i is the number in the desired color's column header in the table below.

Color table颜色表
Intensity01234567
NormalBlackRedGreenYellowBlueMagentaCyanWhite
BrightBlackRedGreenYellowBlueMagentaCyanWhite

The following examples can be used with the printf utility, where \x1b[ implements the CSI: To switch the foreground color to black, use \x1b[30m; to switch to red, use \x1b[31m; utilizing the "bold" parameter, gray would be \x1b[30;1m; to get bold red, use \x1b[31;1m. To reset colors to their defaults, use \x1b[39;49m (or reset all attributes with \x1b[0m).

\033[0m 重置为正常
\033[1m 设置高亮度或加粗
\033[4m 下划线
\033[5m 闪烁
\033[7m 反显
\033[8m 消隐
\033[30m -- /33[37m 设置前景色
\033[40m -- /33[47m 设置背景色

\e 指代Escape，对应八进制\033，对应十六进制\x1b

1、$echo -e "\033[1;31;42mMine is red \e[0m" 高亮绿底红字 2、$ echo -e "\033[4mm is red"

3、\$ echo -e "\x1b[0m"