Using the clear
command on the terminal only fools the user into thinking the screen has been cleared...you can still see output from the previous commands when you scroll using the mouse. This makes life difficult when you are drowning in a tsunami of text.
Various solutions (escape code etc.) which can be found on the Internet are only variations of what the clear command already does.
So how do you clear the contents of a terminal in Linux for real?
From the Windows command line or MS-DOS, you can clear the screen and all commands using the CLS command.
Clear Terminal You can also use the keyboard shortcut “Ctrl + L” to achieve the same as the clear command.
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"'
\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.
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
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.
Try reset
. It clears up the terminal screen but the previous commands can be accessed through arrow or whichever key binding you have.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With