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?
This question is related to
linux
ubuntu
terminal
gnome-terminal
konsole
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.)
My favorite 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.
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.
Compile this app.
#include <iostream>
#include <cstring>
int main()
{
char str[1000];
memset(str, '\n', 999);
str[999] = 0;
std::cout << str << std::endl;
return 0;
}
Try reset
. It clears up the terminal screen but the previous commands can be accessed through arrow or whichever key binding you have.
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.
tput reset
That will do the trick!
echo -e "\e[3J"
This works in Linux Machines
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:
Just to add that tmux
scroll buffer does not clear with clear
, reset
or printf
. You need to :clear-history
. See link.
Source: Stackoverflow.com