Clear a terminal screen for real [closed]

Use the following command to do a clear screen instead of merely adding new lines …

printf "\033c"

yes that’s a ‘printf’ on the bash prompt.

You will probably want to define an alias though…

alias cls="printf "\033c""

Explanation

\033 == \x1B == 27 == ESC

So this becomes <ESC>c which is the VT100 escape code for resetting the terminal. Here is some more information on terminal escape codes.

Edit

Here are a few other ways of doing it…

printf "\ec" #\e is ESC in bash
echo -en "\ec" #thanks @Jonathon Reinhart.
# -e    Enable interpretation of of backslash escapes
# -n    Do not output a new line

KDE

The above does not work on the KDE console (called Konsole) but there is hope! Use the following sequence of commands to clear the screen and the scroll-back buffer…

clear && echo -en "\e[3J"

Or perhaps use the following alias on KDE…

alias cls="clear && echo -en "\e[3J""

I got the scroll-back clearing command from here.

Leave a Comment