How can I clear the scrollback buffer in konsole from bash?

8

4

I'm a heavy bash user and konsole is my preferred environment. I know I can use the keyboard command ctrl+shift+x to clear the scrollback buffer, but there's certain points in my scripts where I would like that to occur. How can I clear konsole's scrollback buffer using the command line, bash, or any other shell?

Joshua K

Posted 2009-10-23T22:12:04.433

Reputation: 771

Answers

13

This will do it:

echo -e "\e[3J"

Found here. Works in regular xterm too.

retracile

Posted 2009-10-23T22:12:04.433

Reputation: 2 586

Doesn't work on Kubuntu 14.04.02 – Autodidact – 2015-04-10T09:04:30.237

1@SandeepDatta: It works with konsole 4.14.3 on Fedora 20; it doesn't clear the screen--it clears the scrollback buffer. – retracile – 2015-04-10T18:36:28.390

As an extension to this answer, I aliased this to the clear command (alias clear="clear && echo -e '\e[3J' && clear") so my screen actually clears now. – Leo C Han – 2015-09-25T15:21:44.260

didn't work for me on SUSE in a xterm with bash shell. – djangofan – 2011-03-19T20:00:07.103

3I liked echo -ne "\e[3J" better as it avoids printed line-break. – Patrick B. – 2012-03-22T12:01:25.130

@PatricB.: true, though in this context, I'm expecting him to incorporate it into a script – retracile – 2012-03-22T16:26:27.723

nice! good find and works perfectly! – Joshua K – 2009-10-24T04:32:37.080

@PatrickB. Thanks for the reminder on the -n. :) – Joshua K – 2013-01-21T20:53:00.830