What does this command? I know that, the
CSI n ; m H is for move the cursor to
n row and
m column, but what does command from title?
That's a visual representation (where
^[ represents the ESC character) of the sequence to clear the screen and bring the cursor to the top in xterm-like terminals at least:
$ TERM=xterm tput clear | cat -v ^[[H^[[2J
To find out about those escape sequences, look at the ctlseqs.txt document shipped with
xterm. There, you'll find:
Control Sequence Introducer (CSI is 0x9b).
CSI Ps ; Ps H
Cursor Position [row;column] (default = [1,1]) (CUP).
CSI Ps J Erase in Display (ED).
Ps = 0 -> Erase Below (default).
Ps = 1 -> Erase Above.
Ps = 2 -> Erase All.
Ps = 3 -> Erase Saved Lines (xterm).
^[[2J doesn't clear the saved lines or alternate screen).
tput clear (or
xterm-like terminals does the same as
printf '\e[H\e[2J'. For that it queries the
terminfo database to know what the sequence of character is for the
clear capability for the terminal whose name is stored in the
$TERM environment variable. If you dump the entry for the
xterm terminal in the
terminfo database with
infocmp xterm, you'll see in it:
$ infocmp -1 xterm | grep clear clear=\E[H\E[2J,
Which is another way to find out about a given escape sequence:
$ infocmp -L -1 | grep J clear_screen=\E[H\E[2J, clr_eos=\E[J,
(here using the
Long name for the capabilities). Then, you can do
man 5 terminfo for a description of those capabilities.
m default to 1 in
^[[H moves the cursor to the home position.
^[[2J clears the screen, leaving the cursor where it is.