Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clear a terminal screen for real [closed]

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?

like image 926
Autodidact Avatar asked Mar 20 '11 06:03

Autodidact


People also ask

What command is used to clear up the terminal window?

From the Windows command line or MS-DOS, you can clear the screen and all commands using the CLS command.

How do I reset my terminal clear?

Clear Terminal You can also use the keyboard shortcut “Ctrl + L” to achieve the same as the clear command.


2 Answers

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"' 

Explanation

\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.

Edit

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 

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...

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.

like image 165
Autodidact Avatar answered Oct 06 '22 21:10

Autodidact


Try reset. It clears up the terminal screen but the previous commands can be accessed through arrow or whichever key binding you have.

like image 21
vpit3833 Avatar answered Oct 06 '22 20:10

vpit3833