How to Stop Ubuntu from Automatically Clearing the Terminal Scrollback Buffer

The Lost Output History

The default terminal emulator in Ubuntu (GNOME Terminal) is a powerful tool for developers and system administrators. However, it handles the execution of certain full-screen terminal applications—like text editors (nano, vim), pagers (less), or system monitors (top)—in a frustrating manner. When you launch one of these applications, it temporarily hijacks the entire terminal window. The problem occurs when you exit the application: the terminal automatically clears the screen and restores the prompt, completely erasing the massive wall of text, compilation errors, or network logs you were looking at just prior to launching the full-screen app. This forces you to re-run previous commands just to see their output again.

Disabling the Alternate Screen Buffer

To force the terminal to behave linearly and stop it from clearing your command history every time you exit a full-screen application, you must disable a feature known as the “alternate screen.”

Unfortunately, GNOME Terminal does not expose this setting in its graphical preferences. You must modify your underlying shell configuration. Open your terminal (Ctrl+Alt+T). You need to edit your bash profile by typing nano ~/.bashrc and pressing Enter. Use your arrow keys to scroll to the very bottom of this file. On a new, empty line, type the following command exactly: export TERM=xterm-color (or alternatively, if you use a specific termcap, you can use a command to disable the `smcup` and `rmcup` capabilities, but the easiest global fix for many users is often appending alias less='less -X' to prevent the pager from clearing the screen). For a universal fix across all apps, add: export TERMINFO=~/.terminfo and compile a custom terminfo without the alternate screen codes. Save the file (Ctrl+O, Enter) and exit (Ctrl+X). Finally, reload the configuration by typing source ~/.bashrc. Your terminal output will now stack sequentially, preserving your vital command history.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.