PuTTY: clear scrollback from commandline
The CSI 3 J
sequence to clear the scrollback buffer was added to PuTTY 0.59. (On the wish request page for this feature see the "fixed-in" line, or go to the PuTTY changes page and search for CSI 3 J
.)
As jwd mentioned, you can enter printf '\033[3J'
on a command line to send this sequence to the PuTTY. Be aware this only clears the scrollback buffer, it doesn't clear the screen. If you have a scroll bar you can actually scroll, then use this sequence, you'll see the scroll bar become disabled because there's suddenly nothing available to scroll to. But the currently displayed screen remains in place.
As jwd mentioned, you can clear both the screen and the scrollback buffer using clear && printf '\033[3J'
If you're accustomed, as I am, to using Ctrl+L for the Reset terminal
option available in PuTTY's system menu, then you might find it helpful to enable Configuration -> Window -> Behavior -> "System menu appears on ALT-Space"
.
Then when you hit Alt+Space, the option for "Clear scrollback"
is triggered by L (lowercase; no Shift). Thus, reset + clear
becomes the charmingly-mnemonic combination of Ctrl+L and Alt+Space L without any pesky mousing or clutter in your shell history.
Create a script file and place it in a path-included folder:
$cat > /usr/local/bin/cls
#!/bin/bash
printf '\033[2J\033[H\033[3J'
Press CTRL+d to save and exit
Change permission on file:
chmod a+x /usr/local/bin/cls
Now you can use the cmd cls
There is an option in PuTTY where you can uncheck the default scrollback behaviour.
Just uncheck the option "Push erased text into scrollback".
After this when you issue the clear
command it will erase the screen and will not put the previous screen contents in the scrollback.
The solution for me was to transmit '\033\143' characters:
printf("\033\143");
This clears the terminal screen and puts the cursor back in the upper left corner.