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
My favourite human friendly command for this is:
reset
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
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.
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:
alias c="printf '\r\n%.0s' {1..50}"
Then, to "clear" away the current contents of the screen (or rather, hide them), just type c+Enter
at the terminal.
With KDE and Ubuntu 12.04 LTS and the "Konsole" terminal, none of the posted answers work. However, pressing default keyboard shortcut CTRL+Shift+X does work! Source:
https://bugs.kde.org/show_bug.cgi?id=288913
Just to add that tmux
scroll buffer does not clear with clear
, reset
or printf
. You need to :clear-history
. See link.
tput reset
That will do the trick!