21

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.

1
  • See @Guillermo answer below: command > clear -x – MountainMan Feb 19 '20 at 21:14
30

Just press Ctrl-L on the keyboard.

4
  • Perfect. Don't know how I missed that. – mcqwerty Jul 28 '11 at 12:58
  • 1
    Excellent. I would have answered just ^L if it weren't for the 30 char minimum! :) – Andy Lee Robinson Jul 28 '11 at 18:11
  • Could have used this since 20 years ago! – Nick Farina Oct 14 '19 at 18:11
  • Current behavriou of ctrl-l in cygwin bash erase scrollback as well. – Trismegistos Oct 21 '20 at 8:18
6

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

1
  • 1
    This is a more complete answer than the accepted one as it tells the command as well along with the keyboard shortcut to achieve it. – RBT Mar 23 '17 at 1:34
5

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.

1
  • Unfortunatelly, current behaviour of a cygwin bash make ctrl-l to erase scrollback as well. – Trismegistos Oct 21 '20 at 8:17
3

Use tput reset

Thanks to this answer: What commands can I use to reset and clear my terminal?

3

In newer versions of clear, it seems that the default behaviour has been changed. To clear the screen and keep scrollback use the option -x. To have the previous behaviour create an alias such as:

alias='clear -x'
1
  • Oh Yeah!!! dis is da BommDiggity! Keeps History and clears screen; just the lone cursor at top. – MountainMan Feb 19 '20 at 21:11
2

If you pipe the output to less, then not only will it clear the screen and show your output at the top, but it will switch back to the previous screen contents when you exit.

1
  • 1
    Good point, less is powerful. But it's not quite what I'm looking for. If it outputs "less" than a full screen it doesn't start at the top and, as you allude to, it doesn't get added to the scrollback. – mcqwerty Jul 26 '11 at 17:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.