To clear the console screen and the scrollback buffer when running PuTTY, this works for me:
echo -en "\ec\e[3J"
This is actually 2 "Esc" sequences that act independently... they can be used in either order:
# clears the console screen, but not the scrollback buffer
# this is actually the escape code to "reset" the terminal
echo -en "\ec"
# clears the scrollback buffer, but not the console screen
# screen content remains, and cursor position remains at its last position
echo -en "\e[3J"
Using echo -en "\ec"
which resets the terminal might change some of your other terminal settings. Instead of "Reset", you could do this:
# position the cursor to "Home" (Top Row, First Column)
echo -en "\e[H"
# Erase down: clear the screen from the cursor down to the bottom of the screen.
echo -en "\e[J"
# Note: this is supposed to clear the screen and position the cursor to home,
# but it didn't work like that for me. It cleared the entire screen (above and
# below the cursor), but left the cursor at its last position.
echo -en "\e[2J"
# putting everything together
echo -en "\e[H\e[J\e[3J"
You can put this in a shell script and it works just fine.
In case there are some system dependencies:
I'm using PuTTY Connection Manager (Version 0.7.1 BETA (build 136)), with PuTTY (Release 0.60).
Typing:
echo \"$TERM\"; /bin/sh --version
reports:
"xterm"
GNU bash, version 4.1.2(1)-release-(x86_64-redhat-linux-gnu) ...
there seems to be a lot of confusion on what exactly is being asked here. can you clarify the question at all? what exactly are you trying to accomplish, clearing your terminal scrollback buffer? (if so, what terminal application are you using?) – quack quixote – 2010-03-24T00:59:01.503
1Ctrl-L will clear the screen in bash (in emacs mode, which is default), similar to executing the clear program. – None – 2010-06-28T07:59:03.763
I know this has been answered to death, but I think what you want is
– jwd – 2017-10-10T15:33:10.947clear && printf '\033[3J'
. No terminal resetting, just clearing the text on the screen. See this post: https://superuser.com/questions/555554/putty-clear-scrollback-from-commandlineJust tested this in the bash terminal in IntelliJ IDE. Works fine and clears the scrollback which is exactly what I wanted. Thanks. – Ian Lewis – 2014-05-21T10:20:19.137