2

This might seem to be a duplicate question but it isn't.

I know that I can use printf "\033f" to clear the scrollback buffer of the "current" session but that doesn't work for old sessions.

My problem is I access several VM's through XVP viewer (a java web browser based VNC) and if I don't make a effort to clear the screen before logging out every time everything can be viewed by scrolling the screen.

Please suggest a way to clear this old scrollback buffer.

PS: Rebooting clears it but I can't do that on production VMs

Jesin
  • 21

2 Answers2

2

Rather than skip several lines, the Linux kernel has since (at least 2011) supported a control sequence which will clear the scrollback:

printf '\033[3J'

It is mentioned in the ncurses changes for July 16, 2011:

    + add E3 extended capability to linux-basic (Miroslav Lichvar)
    + add linux2.2, linux2.6, linux3.0 entries to give context for E3 -TD

and explained in the terminal database:

# The 3.0 kernel adds support for clearing scrollback buffer (capability E3).
# It is the same as xterm's erase-saved-lines feature.
linux3.0|linux 3.0 kernels,
        E3=\E[3J, use=linux2.6,

That came up in the context of a bug report where it was noted that a feature added to xterm in June 1999 would be useful for improving security of applications on the Linux console.

Subsequently (in 2013), the E3 feature was added to the clear utility, so that (depending on which terminal description is used) the utility would clear the scrollback. The comment about Ctrl+l refers to a bash shortcut which may hardcode the same escape sequence (since the terminal database does not tie the clear (or ed) and E3 capabilities together).

Further reading:

Thomas Dickey
  • 76,765
0

I found another way of doing this. Basically the console screen has 510 lines of buffer (in my case), so echoing 511 times fills all those lines clearing the old data.

I'm using echo inside a for loop

for i in {0..510}
 do
    echo
 done

On old bash prompts seq can be used.

for i in `seq 0 510`
 do
    echo
 done
Joseph R.
  • 39,549
Jesin
  • 1