Skip to main content
ansicode

EL — Erase in line (\x1b[K)

Erase part or all of the current line.

Byte forms

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

\\x1b[\x1b[NK
\\033[\033[K
\\e[\e[K
ESC [ESC [ N K
hex1b 5b <N> 4b

Description

Final byte `K`. N = 0 erases from the cursor to the end of the line (default), N = 1 erases from the start of the line up to and including the cursor, N = 2 erases the entire current line. The cursor itself is NOT moved by EL — combine with `\r` if you want to overwrite the line from the start.

Spec citation: ECMA-48 §8.3.41 (EL)

Examples

bash
printf 'progress... \r\033[Kdone\n'
python
import sys, time\nfor i in range(3): sys.stdout.write(f'\r\x1b[K{i}'); sys.stdout.flush(); time.sleep(0.2)\nprint()
go
fmt.Print("\r\x1b[Kclear line\n")
javascript
process.stdout.write('\r\x1b[Kclear line\n')
c
printf("\r\x1b[Kclear line\n");

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 · 3. Erase — ED `J` and EL `K`