Alasdair Macintyre

Student and web developer based in York, UK

« Back to blog

GNU Screen: Split Screen Terminal

GNU Screen is a terminal application for running persistent, multiple sessions inside a single terminal (or in the most useful case, a ssh connection)

Running Screen:

apt-get install screen: installs screen on Debian
screen: starts a new screen session
screen -r: reattaches to an existing screen session
screen -x: reattaches to an existing screen session where the original session is still attached (happens when screen has not been properly detached)
Ctrl-a d: detaches from a running screen session (note this will lose split screen placement - this is the only way I've found to avoid that)

Creating and switching between terminal sessions:

Ctrl-a c: Create new terminal session
Ctrl-a n: Switch to next running terminal session (also Ctrl-a space)
Ctrl-a p: Switch to previous running terminal session
exit: This will close the running terminal session, as usual.

Split Screen:

Ctrl-a |: Split screen vertically (note this one isn't in all screen versions - it is in the Debian one however)
Ctrl-a S: Split screen horizontally
Ctrl-a Tab: Switch to the next screen
Ctrl-a X: Remove active bit of split screen (opposite from | and S)

Copy and Paste:

Screen supports copy and paste between terminal sessions. Copying from a vertically split screen from an ssh session (as in to a different application on your client operating system) can be tricky if it extends over multiple lines, as you'll get the stuff from the other terminal too - , although I've yet to try it.

Ctrl-a [: Starts copy mode. Press enter/space to start, enter/space again to end.
Ctrl-a ]: Paste
Ctrl-a <: Copy from a file
Ctrl-a >: Paste to a file

Other:

Ctrl-a ?: Command reference (also see the manual)

Copy mode can also be used to view the scrollback buffer: after Ctrl-a [ you can use the arrow keys to scroll up to its limits - Esc exits without copying.

Nov 10, 2009
David Somers said...
Oh, I never knew Ctrl-a Tab switches between windows. I always bound :focus down to a key instead. Haha.

Also, did you know that Ctrl-a Space switches to the next terminal session too? Can be quicker than Ctrl-a n as you can do it with one hand :)

Nov 10, 2009
Hmm never knew that, though only time I ever use it is when I've lost the last screen session somehow. Incidentally, have found screen -x will restore when an SSH session has lost the current screen session but not released it for screen -r (happens with Putty and Vista with distressing regularity) - believe it was initially meant for having the same screen session open on multiple computers. Will add both to the article above.
Nov 10, 2009
David Somers said...
Yeah, screen -x is 'Resume to already attached screen session'. Also, if you run lots of screens; screen -S somename gives the screen a name. You can then use screen -ls to list the current screen sessions (and their status).