1. Overview

In this tutorial, we’ll look at different ways to increase the scrollback buffer on a GNU screen session.

2. Limited Scrollback Buffer on a screen Session

The screen command-line tool is a Linux command that multiplexes a single terminal into several pseudo terminals. On each screen session, the scrollback buffer is limited to a default value of 1024 lines. In other words, without configurations, we cannot scroll back further than 1024 lines of output in a screen session.

We can verify the scrollback buffer value of the current session we are in using the command CTRL+A followed by the key i.

Once we’ve entered the command, a small pane will pop up at the bottom left of the screen with a series of numbers. Then, we can read the scrollback buffer value as the number to the right of the first + sign:

increased buffer

As we can see, our current scrollback buffer is at 1024 lines. So let’s look at how we can change the number using different methods.

3. Increase Scrollback Buffer Interactively

One way to change the scrollback buffer is to do it interactively. Specifically, we can configure the scrollback buffer interactively by entering the scrollback command. To do that, we first go into the command input mode using CTRL+A followed by the colon (:) key.

Once we’re in the command input mode, we’ll see a colon prompt appear at the bottom left of the screen:

command prompt

Then, we can increase the scrollback buffer to 5000 lines by entering the command scrollback 5000 to the command input prompt and pressing enter:

scrollback

To verify that the command has indeed taken effect, we can check the scrollback buffer value using the CTRL+A and i key:

increased buffer

One downside to this method is that the change only affects the current session. In other words, any subsequent session we create will still have its scrollback buffer set to the default value.

Let’s look at an alternative method that allows us to change the default value permanently.

4. Increase Scrollback Buffer Using .screenrc

Another way of changing the scrollback buffer is by appending the line defscrollback  in the .screenrc configuration file.

Whenever the screen command launches a new window, it will consult the configuration set in .screenrc. Therefore, by setting the default scrollback value in the .screenrc file, we can configure all the new sessions’ scrollback values.

For example, we can change the default scrollback value to 5000 by appending defscrollback 5000 to the .screenrc file:

$ echo "defscrollback 5000" >> ~/.screenrc

If the .screenrc file already exists, the command appends the new configuration to the file. This ensures the existing configurations are kept intact. On the other hand, the command creates the .screenrc file in the user’s home path if the file is not found.

We can then launch a new screen session and verify that its scrollback value indeed defaults to 5000 lines.

Note that this method will only change the scrollback buffer for newly created windows. In other words, any existing session will not have its scrollback buffer changed with this method.

5. Summary

In this tutorial, we first learned that the screen command places a limit on how far back we can scroll on every session. Then, we’ve seen how we can interactively increase the scrollback buffer on the current session. Finally, we looked at configuring the .screenrc file with the defscrollback directive to change the default scrollback buffer for all the new sessions.