I can issue the clear
command or press Ctrl + L to clear the current Ubuntu terminal, but this just shifts previous output upwards and if you use mouse scroll or PgUP and PgDown keys it's hard to distinguish where the output of previous command ends and output of current command begins.
Is there a way to really clear the terminal so I won't see previous command results?
Yes, the command you're looking for is
In contrast to
clear
, or Ctrl+L,reset
will actually completely re-initialise the terminal, instead of just clearing the screen. However, it won't re-instantiate the shell (bash). That means that bash's state is the same as before, just as if you were merely clearing the screen.As @Ponkadoodle mentions in the comments, this command should do the same thing more quickly:
From the other answers:
You can set a Keyboard Shortcut to
reset
the terminal, as explained by towolf.If you're running Kubuntu, and your terminal is Konsole, you need to go to Edit → Clear history, since
reset
doesn't work the same way there, as UncleZeiv notes.I was looking for this for a while and I found some genius that posted this:
Clears the whole screen buffer, very clean. Works on OS X and believe it works fine on most *nix terminals.
For curious, this part
'\e[3J'
is a terminal escape command.You can also assign a shortcut in gnome-terminal by going to Edit → Keyboard Shortcuts. I useShift+Ctrl+Alt+C.
Cross posting my answer from stackoverflow.
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.
run this command:
This has the same effect as launching a new terminal.
My favorite is
printf "\ec"
. This can also beprintf "\033c"
orprintf "\x1bc"
. That is an ansi escape sequence that miraculously clears the screen and buffer for the terminal output (for most standard terminals I have worked in it seems - I know it works in such as gnome-terminal, terminator, xterm, etc. on Ubuntu-like Linuxes)I know this works in Linux Mint and Ubuntu 14.04, so I don't know why people are appending and prepedning things like
clear && echo -ne "\033c
.printf "\ec"
has always worked for me.Additionally, in my
.bashrc
I have a binding like this:Now I press ctrlt all the time.
Here are all the ways you can clear the terminal screen in Unix:
Well it really depends, if you are using
Konsole
for instance evenreset
doesn't prevent you to scroll past the first line. In that case you have to use some feature of the particular terminal you are using. ForKonsole
, it'sEdit > Clear History
.I have found the following to be quite successful with Kubuntu:
You can use
cls
to keep with the Windows tradition, use the Matlab versionclc
, or one of your own. Good luck!If you're using yakuake or Konsole, try Ctrl+Shift+K.
Source: https://bugs.kde.org/show_bug.cgi?id=309008