36

I use the screen command for command-line multitasking in Linux and I set my scrollback buffer length to a very large value. Is there a key combination to clear the buffer for a certain tab when I don't want it sitting there anymore?

Jason Plank
  • 2,336
  • 5
  • 31
  • 40
  • See http://stackoverflow.com/questions/10932487/gnu-screen-how-to-clear-scrollback-and-screen-at-once for how to clear the screen at the same time. – Alastair Irvine Mar 02 '17 at 02:01

7 Answers7

61

This thread has the following suggestion:

In the window whose scrollback you want to delete, set the scrollback to zero, then return it to its normal value (in your case, 15000).

If you want, you can bind this to a key:

bind / eval "scrollback 0" "scrollback 15000"

You can issue the scrollback 0 command from the session as well, after typing C-a :. HTH.

Shawn J. Goff
  • 4,635
  • 8
  • 34
  • 38
Zsolt Botykai
  • 50,406
  • 14
  • 85
  • 110
  • Excellent, I didn't know you could change it on the fly! – Greg Hewgill Sep 22 '08 at 06:35
  • 12
    Google aside, the purpose of Stack Overflow is to be the place for canonical answers, so I for one am fine with things being duplicated in a place where I know they can be found. – Drew Stephens May 17 '09 at 16:55
  • That's why I had wuoted the solution as well. And we could argue about google but with those simple keywords it was the very first hit for me. And actually I had read that message on the mailing list when it was posted, that's why I had remembered. – Zsolt Botykai May 17 '09 at 20:09
  • A dumber but easier to remember / type alternative `yes | head -100000`, or just `yes | cat -n`, or `seq 1 999999` and Ctrl-C when you see a number higher than your scrollback length. Only on a local terminal though, might be too slow on a remote connection. Assuming you want to purge sensitive info. from the scroll back - if you just want an empty scroll back, the answer's the way to go. – Terry Brown Oct 27 '18 at 14:56
15
  • C-a C will clear the screen, including the prompt
  • clear (command, not key combination) will clear the screen, leaving a prompt

ETA: misread the original question; these will just clear the visible text, but will not clear the buffer!

Athena
  • 3,130
  • 1
  • 19
  • 17
  • None of those clear the scrollback buffer though; and the second one creates a new screen window, leaving the previous one still there (press `C-a a` to get back to it). – Greg Hewgill Sep 22 '08 at 06:27
  • I misread the original question, and made a mistake with the second -- thought I could clear that out before spreading the misinformation, but I underestimated how fast people are here :-) (FTR, my original comment had `C-a c` as another solution) – Athena Sep 22 '08 at 06:36
  • 3
    I noticed there's a difference between `C-a c` (Ctrl-C + lowercase c) and `C-a C` (Ctrl-C + uppercase C). The lowercase one creates a new screen window and a new shell, and the second one actually clears the current window. – elifiner Feb 09 '15 at 13:19
11

I added the command "clear" as well to clean the current screen. N.B. You have to press enter to regain you prompt.

bind '/' eval "clear" "scrollback 0" "scrollback 15000"

Also add it to you ".screenrc" to make it permanent.

N.B. I added single quotes around the slash to be sure it didn't interfere in my ".screenrc". May not be necessary.

Jon B
  • 51,025
  • 31
  • 133
  • 161
user1788889
  • 111
  • 1
  • 3
  • That's not what the OP asked for. This is not an answer - the bit that is duplicates the other answers. – itsbruce Oct 31 '12 at 15:11
0

alias cls='printf "\e[3J\033c"'

Clears the screen and scrollback buffer.

-1

Command-K seems to be best solution for Mac. For more details and explanations, please refer to this page.

Community
  • 1
  • 1
Robert White
  • 125
  • 1
  • 5
-3
^a : clear

worked for me on Ubuntu.

Floern
  • 33,559
  • 24
  • 104
  • 119
-6

From the man page:

C-a C       (clear)       Clear the screen.