How to really clear the terminal?

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?

user313885 asked Feb 6, 2011 at 21:51 15.2k 17 17 gold badges 47 47 silver badges 43 43 bronze badges Press Ctrl+L twice and you get blank! Commented Jul 30, 2014 at 12:19 On mac os and iTERM, cmd + k does the trick for me. Commented Feb 3, 2021 at 0:53 ctrl+L twice works on mac os x vscode integrated terminal Commented Mar 6, 2021 at 10:06

To clarify the MacOS commands: cmd.K - clear terminal, can't scroll up || ctrl.L - clear screen, scroll up for history || multiple ctrl.L - clear multiple screens. Can see the empty prompt for each clear, and will be able to see history prior to the number of clears

Commented Feb 12, 2022 at 23:01

12 Answers 12

Yes, the command you're looking for is

reset 

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:

tput reset 

From the other answers:

15.4k 11 11 gold badges 54 54 silver badges 91 91 bronze badges answered Feb 6, 2011 at 21:55 Stefano Palazzo Stefano Palazzo 87.4k 46 46 gold badges 211 211 silver badges 227 227 bronze badges Probably doesn't matter for most users, but the behavior of reset is dependent on the terminal. Commented Feb 7, 2011 at 13:44

Personally I don't mind that something is left "up" along the scroller when I hit ^L . I don't see it (that's what I want!), I don't feel it, and if suddenly I would need to restore what was there — no problem. reset in contrast is much harder tool — I'll use it when something went wrong with the terminal — like, when weird escape sequences accidentally ruined the display altogether.

Commented Feb 7, 2011 at 13:56

@ulidtko: it does matter when you run consecutive sessions of programs with tons of output. If you scroll back it's easy to get confused about which execution printed something. I know perfectly well that more sophisticated solutions could be used in these cases, but nonetheless it's a scenario that comes about pretty often in quick & dirty debugging sessions.

Commented Feb 9, 2011 at 12:49

There's also tput reset which visibly does the same thing, but completes instantaneously (whereas reset can take up to about 2 seconds before the prompt reappears).

Commented Mar 4, 2016 at 22:57 This causes my putty.exe window to resize, would be nice to clear without that happening. Commented Aug 3, 2017 at 20:11

I was looking for this for a while and I found some genius that posted this:

clear && printf '\e[3J' 

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.

107 4 4 bronze badges answered May 29, 2014 at 5:51 1,991 1 1 gold badge 11 11 silver badges 6 6 bronze badges Hmm, works in xterm, Konsole and Linux VT, but doesn't in gnome-terminal. Commented Jun 24, 2014 at 13:02 Thanks, that's super useful! What does printf '\e[3J' mean? How does it clean the buffer? Commented Jul 24, 2015 at 17:03

Great find! And for those who want the Bash-style reset on mac: nano ~/.bashrc and add alias reset="clear && printf '\e[3J'"

Commented Aug 12, 2016 at 5:43

be careful aliasing reset -- it does more than just clear the terminal. for example, if you accidentally print a binary file with random garbage that corrupts the terminal (e.g. disables echoing of typed characters), reset can usually fix that. of course aliasing is fine as long as you know how to \override an alias-shadowed command.

Commented Oct 3, 2016 at 12:51 This is the only answer that works to clear Putty scrollback when accessing some SSH via Winders. Commented Jan 19, 2017 at 15:56

You can also assign a shortcut in gnome-terminal by going to Edit → Keyboard Shortcuts. I use Shift + Ctrl + Alt + C .

reset and clear shortcut

104k 37 37 gold badges 253 253 silver badges 423 423 bronze badges answered Feb 8, 2011 at 22:46 667 4 4 silver badges 4 4 bronze badges

+1. I always have the Menubar hidden; so even after years and years of using gnome, I never thought to look for this. Thanks :-)

Commented Feb 9, 2011 at 12:53

“Reset” do nothing for me, and “Reset and Clear” clear everything but does not re‑display the prompt. None of these menu entries behave like the “reset” command from a terminal.

Commented Jul 9, 2014 at 8:50

As @Hibou57 said, my keyboard shortcut for "Reset" doesn't seem to do anything. Is this functionality broken in 14.04?

Commented Aug 23, 2014 at 20:37 “Is this functionality broken in 14.04?”: this is the same with 12.04. Commented Aug 24, 2014 at 2:53

@Hibou57 "Reset and Clear" isn't expected to re-display the prompt, but if you hit Enter afterwards it should re-display the prompt. Does that work for you?

Commented Nov 9, 2016 at 2:32

Cross posting my answer from stackoverflow.

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

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.

answered Oct 13, 2015 at 8:08 Autodidact Autodidact 438 5 5 silver badges 10 10 bronze badges

run this command:

reset 

This has the same effect as launching a new terminal.

answered Feb 6, 2011 at 21:55 37.4k 13 13 gold badges 100 100 silver badges 153 153 bronze badges

When using putty, after running reset , I can still scroll up and see previous stuff. Is this an issue with PuTTY rather than reset ?

Commented Feb 7, 2011 at 14:43 @svish -- that's just a putty implementation issue or decision. Commented Feb 8, 2011 at 22:52 @jgbelacqua, Deal :) Commented Feb 9, 2011 at 9:27 Worked with MAC OS Terminal Commented Jan 11, 2019 at 2:15

@Bira No, reset doesn't clear the scrollback on macOS 10.14 Mojave. You could try seq 100; reset to see scrollback still there. On macOS terminal, Cmd+K can clear screen and scrollback.

Commented Jan 24, 2019 at 4:23

My favorite is printf "\ec" . This can also be printf "\033c" or printf "\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:

bind -x '"\C-t": printf "\ec"'; 

Now I press ctrl t all the time.

answered May 1, 2015 at 9:32 266 2 2 silver badges 6 6 bronze badges

Do you know how could a mapping be created using the Windows key ? This snippet is really great, works exactly like Command-K on mac. Thank you.

Commented Jan 12, 2017 at 15:47

@Niloct you can see if the terminal supports it with xev (just type xev in a terminal inside an x-session). From what I could tell, urxvt doesn't support it; while I didn't try in a tty, I am confident it would not be supported. I also doubt xterm or gnome-terminal would support this. It's tricky with ansi-escapes. Cheers and sorry for late reply.