How do I clear the Gnome terminal history?

70,017

Solution 1

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.

Solution 2

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

Solution 3

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.

Solution 4

Anthon's answer works in KDE Konsole, but not urxvt. In urxvt, I've been using reset for a few years to clear the scrollback (along with all the other things it does), and wasn't satisfied that it didn't work in Konsole. So now for Linux I have a new alias:

alias allclear='clear; echo -e "\033c\e[3J"'

But it doesn't work on OS X.

tput reset doesn't work in any context AFAICT.

In KDE Konsole, ctrl-shift-k clears the scrollback (including the current shell prompt, so it's completely empty). In iTerm or Apple's terminal on OS X, cmd-shift-k also clears scrollback. To add this feature to urxvt, add this to ~/.Xresources:

urxvt*keysym.C-S-K: command:\033c

Solution 5

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:
70,017

Related videos on Youtube

hpn
Author by

hpn

Updated on September 18, 2022

Comments

  • hpn
    hpn over 1 year

    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?

    • Admin
      Admin over 7 years
      It's terminal dependent, and none of the answers address that.
  • Toothrot
    Toothrot over 7 years
    What's the difference between reset and tput reset?
  • Iván Rodríguez Torres
    Iván Rodríguez Torres over 7 years
    tput reset is faster than reset in Ubuntu 16.04, at least
  • João Pimentel Ferreira
    João Pimentel Ferreira almost 7 years
    -1, you can still see the buffer if you scroll up
  • KLaw
    KLaw over 6 years
    This answer is the answer that anybody using Linux Bash will love if they are expecting the same result as they would receive on a Mac by pressing command + K. I went ahead and turned this into a standalone command by adding the following function to the bottom of /etc/bash.bashrc (then log out of server, log back in and it will work via the command allclear): allclear(){ ` echo "Clearing terminal and scrollback..."` ` sleep 1.5` ` clear; echo -e "\033c\e[3J"` } ` Edit: Can't get formatting to work. If anybody is able to edit this so it is readable, I would appreciate it.
  • Paradox
    Paradox about 5 years
    The least you can do is explaining and formatting your answer.
  • G-Man Says 'Reinstate Monica'
    G-Man Says 'Reinstate Monica' about 5 years
    (1) It is not clear that the OP wants to delete the shell’s memory (history) of previous commands (the question is about the terminal).  You can’t see it, but history -c has been presented in two previous answers, and they were deleted for not being correct answers to the question.  (2) While closing the terminal window will (probably) erase the terminal’s memory of previous commands, it’s far from apparent that the OP wants to do that. … And P.S. A single exit command isn’t guaranteed to close the terminal window.