Session Control using Screen

Normally when you log out from a session on a Linux system, any processes of yours that are still running get terminated.  When you have long-running jobs, you may wish to log out while leaving those jobs running, and come back later to see how they are doing.

Between nohup and screen, screen is the more complicated of the two, by far, but once learned gives much greater flexibility and control over your sessions.

Starting and Quitting Screen

To start a new screen session, just type screen and hit enter.  You'll see a notice giving you the version and license information, and you can hit enter to dismiss this, and then you will be in a shell session inside screen.

To disconnnect, simply type exit to end the current shell.  You'll see the message [screen is terminating] and you'll be returned back to your normal shelll session.

Disconnecting and Reconnecting from a Screen Session

Instead of quitting screen entirely, you can detach your current terminal from the screen session, leaving any processes you launched running, and reconnect later seeing any output that may have resulted in the interim.  To do so, hit ctrl-a then d.  ctrl-a is the meta key, indicating that you're entering a screen command.  See the section about ctrl-a for more information

To reconnect to an existing screen session, you can type screen -x or screen -r.  Note if you have more than one screen session running you'll need to specify which one you want to reconnect to.  See below for more information.

ctrl-a

All of the commands you want to issue to screen itself while inside a screen session begin with a ctrl-a followed by a further keypress or key combination.  For example as mentioned above, to tell screen you want to detatch leaving screen running, as mentioned above, you hit ctrl-a d.  There's a huge number of commands available to you, and you can see a summary of them when attached to a screen session by hitting ctrl-a ?.

Finding Existing Screen Sessions

Using Multiple Windows in a Single Screen Session

Scrollback/Logging in a Screen Session