Clearing terminal

5,780

Solution 1

Try printf '\033c'. This sends an escape sequence to the terminal, usually clearing all contents, including scrollback buffer.

Solution 2

clear DOES clear the terminal screen. I guess you're accessing the Terminal from a graphic interface and hence you're actually using an interface to the console, not the actuall console. This interface automatically "saves" your output history (The stuff you see when scrolling up). In a real console (no graphic interface), you can't just scroll up. In this case, the terminal is just a program that keeps logs of the console output.

If you open up a new Terminal window and close the current one, you'll start off with a fresh window. (You could also reinitialize manually by going to Terminal -> Reinitialize and clear")


Terminal running in Desktop Environment: enter image description here

Console without Desktop Environment: enter image description here

Share:
5,780

Related videos on Youtube

Max
Author by

Max

Analytics consultant available for hire. More info: https://maxcorbeau.com

Updated on September 17, 2022

Comments

  • Max
    Max over 1 year

    I would like to issue a command from a bash script to clear the terminal it is running from:

    • I don't want to clear the bash history (history -c)
    • I don't want to issue the clear command (which moves the terminal down to the last prompt, giving the impression the terminal has been cleared, but previous output remains visible if you scroll up)
    • I want to completely remove all previous output to my terminal and have it clean as if I was opening a new one

    Thanks.

  • HikeMike
    HikeMike over 13 years
    On my OS X system, this is no different that clear.
  • Šimon Tóth
    Šimon Tóth over 13 years
    Well, it shouldn't. The difference is that clear is a command, tput isn't a direct command, instead it generates a string that is then interpreted by the terminal.
  • Thom G
    Thom G over 13 years
    And how would you do that from a bash script? Btw., the virtual console has some kind of scrollback (shift-pgup/pgdn).
  • Pylsa
    Pylsa over 13 years
    @Maxelost You can not, the bash script can't manipulate the terminal window directly. The Terminal window merely "emulates" a Console. Terminal != Console. Everything to see when you scroll up in the Terminal window is a mere record the Terminal window keeps. It's not done by the Console.
  • Šimon Tóth
    Šimon Tóth over 13 years
    But the OP doesn't want to clear the terminal, he wants to clear the history buffer.
  • Pylsa
    Pylsa over 13 years
    @Let_Me_Be as I'm trying to make clear, there is no native way. To clear the Terminal Window's history from bash
  • Šimon Tóth
    Šimon Tóth over 13 years
    This is just a simple reset. Reset doesn't clear scrollback.
  • Thom G
    Thom G over 13 years
    @Let_Me_Be: I never experienced that it didn't. Tried just now -- works fine in xterm, rxvt and gnome-terminal.
  • Craig Gillikin
    Craig Gillikin over 13 years
    tput clear will clear the screen, but not the scrollback.