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?
My favourite human friendly command for this is:
Tested on xterm and VT100. It also helps after an abnormal program termination. Keeps the command buffer, so up-arrow will cycle through previous commands.
cheers :D
None of the answers I read worked in PuTTY, so I found a comment on this article:
In the settings for your connection, under "Window->Behavior" you'll find a setting "System Menu Appears on ALT alone". Then CTRL+L,ALT,l (that's a lower case L) will scroll the screen and then clear the scrollback buffer.
(relevant to the OP because I am connecting to an Ubuntu server, but also apparently relevant no matter what your server is running.)
Use the following command to do a clear screen instead of merely adding new lines ...
yes that's a 'printf' on the bash prompt.
You will probably want to define an alias though...
Explanation
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...
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...
Or perhaps use the following alias on KDE...
I got the scroll-back clearing command from here.
The following link will explain how to make that alias permanent so you don't have to keep typing it in.
https://askubuntu.com/questions/17536/how-do-i-create-a-permanent-bash-alias
These are the steps detailed at that link.
I take no credit for this information just passing it along.
I know the solution employing printing of new lines isn't much supported, but if all else fails, why not? Especially where one is operating in an environment where someone else is likely to be able to see the screen, yet not able to keylog. One potential solution then, is the following alias:
Then, to "clear" away the current contents of the screen (or rather, hide them), just type
c+Enter
at the terminal.Try
reset
. It clears up the terminal screen but the previous commands can be accessed through arrow or whichever key binding you have.