Skip to main content
ansicode

ED — Erase in display (\x1b[2J clear screen)

Erase part or all of the screen.

Byte forms

Every common string-literal form so you can paste-and-search either direction.

\\x1b[\x1b[NJ
\\033[\033[2J
\\e[\e[2J
ESC [ESC [ N J
hex1b 5b <N> 4a

Description

Final byte `J`. Parameter N controls scope: 0 = cursor → end of screen (default), 1 = beginning of screen → cursor, 2 = entire visible screen, 3 = entire screen + scrollback buffer (xterm extension). `\x1b[2J` is the canonical 'clear screen' but leaves the cursor where it was — most clear-screen recipes combine it with `\x1b[H` to also reset the cursor to (1,1). On modern terminals prefer `\x1b[2J\x1b[H` over the legacy `\033c` (RIS) which performs a full terminal reset including SGR and charset.

Spec citation: ECMA-48 §8.3.39 (ED)

Examples

bash
printf '\033[2J\033[H'
python
print('\x1b[2J\x1b[H', end='')
go
fmt.Print("\x1b[2J\x1b[H")
javascript
process.stdout.write('\x1b[2J\x1b[H')
c
printf("\x1b[2J\x1b[H");

Terminal support

xterm
yes
Linux console (fbcon)
yes
macOS Terminal.app
yes
iTerm2
yes
Windows Terminal
yes
cmd.exe / ConPTY
yes
kitty
yes
alacritty
yes
WezTerm
yes
Ghostty
yes
GNOME Terminal
yes
Konsole
yes
tmux
no
GNU screen
no

Related sequences

In the family cookbook

CSI cookbook · 1. The envelope — `\x1b[` … `<final-byte>`