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[2JESC [
ESC [ N Jhex
1b 5b <N> 4aDescription
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
printf '\033[2J\033[H'print('\x1b[2J\x1b[H', end='')fmt.Print("\x1b[2J\x1b[H")process.stdout.write('\x1b[2J\x1b[H')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
| xterm | Linux console (fbcon) | macOS Terminal.app | iTerm2 | Windows Terminal | cmd.exe / ConPTY | kitty | alacritty | WezTerm | Ghostty | GNOME Terminal | Konsole | tmux | GNU screen |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| yes | yes | yes | yes | yes | yes | yes | yes | yes | yes | yes | yes | no | no |