T.06 · Terminal Fundamentals

GNU screen

The predecessor to tmux. Still found on older systems and locked-down servers where you can't install anything new.

GNU screen was released in 1987 and was the standard terminal multiplexer for two decades. Most new work today uses tmux instead — better defaults, cleaner config, more active development — but screen is still everywhere. It's pre-installed on most older Linux distributions, on locked-down systems where you can't add packages, and on legacy servers that have been running undisturbed for years.

The concepts are identical to tmux: sessions you can detach from and reattach to, multiple windows, the ability to split. Only the keystrokes differ.

When you'll encounter it

The first five minutes

$ screen # start a new session $ screen -S lab3 # start a new named session called "lab3" $ screen -ls # list existing sessions $ screen -r # reattach the most recent session $ screen -r lab3 # reattach a specific named session $ screen -d -r lab3 # force-detach (steal it from another attached client) and reattach

The prefix key

Screen's prefix is Ctrl+a (rather than tmux's Ctrl+b). Press Ctrl+a, release, then press the command key. People who use both tools usually remap tmux's prefix to Ctrl+a to match screen.

Cheat sheet

screentmux equivalentWhat it does
Ctrl+a dCtrl+b dDetach (session keeps running)
Ctrl+a cCtrl+b cCreate a new window
Ctrl+a nCtrl+b nNext window
Ctrl+a pCtrl+b pPrevious window
Ctrl+a 0..9Ctrl+b 0..9Jump to window 0..9
Ctrl+a ACtrl+b ,Rename current window
Ctrl+a "Ctrl+b wInteractive window picker
Ctrl+a SCtrl+b "Split horizontally
Ctrl+a |Ctrl+b %Split vertically
Ctrl+a TabCtrl+b arrowMove to next pane region
Ctrl+a XCtrl+b xClose current region
Ctrl+a [Ctrl+b [Enter copy/scroll mode
Ctrl+a ?Ctrl+b ?Show all key bindings
Ctrl+a kCtrl+b &Kill current window (asks first)
The split-pane gotcha. In screen, splitting creates a region, but that region is empty until you focus it and start a new shell with Ctrl+a c (or attach a window to it with Ctrl+a "). In tmux, splitting creates a pane that immediately spawns a shell. Screen's split workflow is fussier; one of the reasons most people prefer tmux.

Saving the scrollback to a file

screen's copy mode (Ctrl+a [) can scroll back through buffered output. To dump it to a file, drop this in your ~/.screenrc and use the hardcopy command:

# In ~/.screenrc — turn on scrollback buffering defscrollback 10000 # Inside a screen session, dump the current window's scrollback to a file Ctrl+a h # quick hardcopy to ~/hardcopy.0 Ctrl+a : hardcopy ~/lab3.txt # dump to a specific filename

When to switch to tmux

If you have a choice between the two on a new system, use tmux. Reasons:

Reasons to know screen anyway: it might be all you have. When you SSH into a box that's eight years old and you need a persistent session before kicking off a long task, screen is on the box and tmux isn't. Knowing the 12 keystrokes above is enough for that.

The point

Screen and tmux solve the same problem with different keystrokes. Learn one well; learn the other's prefix and split commands so you can survive on a system where you don't get a choice.

For your day-to-day work, default to tmux. For the legacy server you SSH into once a year, screen is right there waiting — and the cheat sheet above will get you through the session.

References

Formatted in APA 7. Alphabetized by first author's last name.

  1. GNU Project. (n.d.). GNU screen manual. Free Software Foundation. https://www.gnu.org/software/screen/manual/screen.html
  2. Kerrisk, M. (n.d.). screen(1): Linux manual page. Linux man-pages project. https://man7.org/linux/man-pages/man1/screen.1.html