How do I clear my bash screen while maintaining scrollback?

The clear command can make the next command easier to read (if it outputs less than a page there's no scrolling hence no searching for the beginning). However it also clears the scrollback buffer which you may not always want.


Just press Ctrl-L on the keyboard.


TL;DR

  • CtrlL to scroll the current line to the top. The scrollback is not erased.

  • clear -x to erase the all the lines that are not in the scrollback.

  • clear to erase all the lines, including the scrollback.


CtrlL is a binding of GNU readline library, which, as Bash manual page says, is what handles reading input when using an interactive shell.

clear-screen (C-L) Clear the screen leaving the current line at the top of the screen.

The CtrlL binding can be reassigned in .inputrc.


clear, on the other hand, is an external command.

$ type clear
clear is /usr/bin/clear

From its manual page,

clear clears your screen if this is possible, including its scrollback buffer (if the extended “E3” capability is defined).

OPTIONS
-x do not attempt to clear the terminal's scrollback buffer using the extended “E3” capability.


the clear command does not clear scrollback for me. so clear or ^L works.