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? ^[[H^[[2J ?


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

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).

(note that ^[[2J doesn't clear the saved lines or alternate screen).

tput clear (or clear) on 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

Which is another way to find out about a given escape sequence:

$ infocmp -L -1 | grep J

(here using the Long name for the capabilities). Then, you can do man 5 terminfo for a description of those capabilities.


The values n and m default to 1 in CSIn;mH, thus ^[[H moves the cursor to the home position. ^[[2J clears the screen, leaving the cursor where it is.

  • Not exactly; ^[[2J clears the screen but does not move the cursor. – egmont Oct 24 '17 at 21:31
  • @egmont You are correct. I edited the answer. – Johan Myréen Oct 25 '17 at 4:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.