Rather than skip several lines, the Linux kernel has since (at least 2011) supported a control sequence which will clear the scrollback:
printf '\033[3J'
It is mentioned in the ncurses changes for July 16, 2011:
+ add E3 extended capability to linux-basic (Miroslav Lichvar)
+ add linux2.2, linux2.6, linux3.0 entries to give context for E3 -TD
and explained in the terminal database:
# The 3.0 kernel adds support for clearing scrollback buffer (capability E3).
# It is the same as xterm's erase-saved-lines feature.
linux3.0|linux 3.0 kernels,
E3=\E[3J, use=linux2.6,
That came up in the context of a bug report where it was noted that a feature added to xterm in June 1999 would be useful for improving security of applications on the Linux console.
Subsequently (in 2013), the E3
feature was added to the clear
utility, so that (depending on which terminal description is used) the utility would clear the scrollback. The comment about Ctrl+l refers to a bash shortcut which may hardcode the same escape sequence (since the terminal database does not tie the clear
(or ed
) and E3
capabilities together).
Further reading: