Skip to content

Your First Session

This chapter delivers the complete round trip once, slowly: start a named session, do something in it, detach, prove from outside that it lives, reattach, and find your work exactly where you left it. Every later chapter is a refinement of these five minutes.

Starting

screen -S first

Your terminal clears, a fresh shell prompt appears, and you are inside. Nothing looks different — that is the point — but three things have changed. A Screen server is now running on this machine, holding your session. Your shell lives in the session's window 0, not in your terminal directly. And the session has the name first, which is how you will address it from outside.

(On a stock install, a copyright notice fills the screen at each start until you press a key. It is a splash, not an error; chapter 8 shows the setting that silences it.)

Try the temperature of the place:

echo inside the session

Detaching for the first time

Press Ctrl-A, then d. Two keystrokes, one meaning: detach.

[detached from 23237.work]

(that is the lab's real line, from transcript t02 — yours names your own session's number and the name first.)

You are back at the shell you started from. It feels as if Screen exited. It did not — and now you prove it from outside, because belief is not required when a tool will show you.

Proof from outside

screen -ls

The lab's transcript of exactly these steps, with a session named work, shows (screen-lab/transcripts/t01-detach-reattach.txt):

There is a screen on:
    23237.work  (10/27/26 03:06:33) (Detached)
1 Socket in /run/screen/S-lab.

Your number and clock will differ; the shape will not. The transcript goes on to print a clock inside the session, so the lines it collects were written while nobody was attached.

Start something slow before reattaching only if you want the full effect — in the transcript it is a loop that prints the time every four seconds, and its output accumulates, unwatched, at the session's own pace.

Reattaching

screen -r first

The session redraws: your shell, your earlier echo, and anything that printed while you were away, all in place. Nothing restarted and nothing was restored from a file — the programs simply never stopped, and this client has reconnected to them (the server and client of chapter 2, earning their keep).

Leaving properly

Two different exits, and the difference matters:

  • ** detach** (Ctrl-A d) leaves the session running for your return. This is the everyday exit.
  • exit — typing exit in the window's shell, or closing every window — ends the session for good. With one window, the shell's exit is the session's end, and screen -ls afterwards reports no sockets.

End this first session with exit, so the slate is clean, and check that screen -ls agrees:

No Sockets found in /run/screen/S-lab.

Check

You can state the round trip from memory: screen -S name to start, Ctrl-A d to detach, screen -ls to list, screen -r name to reattach, exit to end. Chapter 5 takes the middle three apart properly — the flags for taking a session away from another terminal, attaching without detaching, and ending a session from outside.