Escape sequences consist of
  1. Escape character; an ASCII control character with the value 0x1B (decimal 27)
  2. Left square bracket
  3. Zero, one, or more numeric arguments. Multiple numeric arguments are separated by semicolons
  4. A one-letter, case-sensitive code specifying the action to take: move cursor, change text color, clear screen, etc.
In the table below, ESC denotes the Escape character.
Escape sequence Action Environments where supported
DOS ANSI.SYS Linux console
ESC[nA Moves cursor up n rows X X
ESC[nB Moves cursor down n rows X X
ESC[nC Moves cursor right n columns X X
ESC[nD Moves cursor left n columns X X
ESC[y;xH Moves cursor to position (x, y). The upper left corner of the screen is (1,1) X X
ESC[2J Clears screen and moves cursor to home position (1,1) X X
ESC[K Erases line; from cursor position (including character under cursor) to end of line X X
ESC[y;xf Same as ESC[y;xH X X
ESC[s Pushes current cursor position on an internal stack X X
ESC[u Pops last cursor position saved by ESC[s and moves cursor to that position X X
ESC[im
ESC[i;jm
ESC[i;j;km
Sets text attributes. i, j, and k may have any of the following values:
i, j, k Attribute i, j, k Attribute
0 All attributes off 1 Bold
4 Underscore (not supported on all displays) 5 Blink
7 Reverse video 8 Concealed video on
30 Foreground color: black 31 Foreground color: red
32 Foreground color: green 33 Foreground color: yellow
34 Foreground color: blue 35 Foreground color: magenta
36 Foreground color: cyan 37 Foreground color: white
40 Background color: black 41 Background color: red
42 Background color: green 43 Background color: yellow
44 Background color: blue 45 Background color: magenta
46 Background color: cyan 47 Background color: white
X X