Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

When we use clear command or Ctrl+L in terminal, it clears terminal but we can still scroll back to view the last used commands. Is there a way to completely clear the terminal?

share|improve this question

5 Answers 5

up vote 23 down vote accepted

You can use tput reset.

Besides reset and tput reset you can use following shell script.

#!/bin/sh
echo -e \\033c

This sends control characters Esc-C to the console which resets the terminal.

Google Keywords: Linux Console Control Sequences

man console_codes says:

The sequence ESC c causes a terminal reset, which is what you want if the screen is all garbled. The oft-advised "echo ^V^O" will only make G0 current, but there is no guarantee that G0 points at table a). In some distributions there is a program reset(1) that just does "echo ^[c". If your terminfo entry for the console is correct (and has an entry rs1=\Ec), then "tput reset" will also work.

share|improve this answer
    
+1 from me, Sachin :-) –  Nikhil Mulley Jan 7 '12 at 17:38

You can use the reset command, that will reset the terminal settings.

share|improve this answer

I know you're on a gnome terminal, but I thought I'd answer with a tip for others who might be (like me) on a Mac:

If you're using Terminal.app or iTerm.app then Control+L will scroll up so the terminal looks blank, but Cmd+K will actually reset the terminal / clear scroll-back.

Or, if you're able to set keyboard preferences for your terminal you may be able to assign something like Ctrl+K to input echo -e \\033c as was mentioned above.

share|improve this answer

I found this on the net years ago, and works well for me. It completely clears the terminal with no scroll history.

echo -e "\e[3J"
share|improve this answer
clear; history -c

will get the job done.

share|improve this answer
    
I'm pretty sure he didn't mean "you can press up to get old commands"; he meant you can scroll up in the terminal to see what it used to display, even after running clear –  Michael Mrozek Feb 26 '13 at 20:41

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.