Use screen to keep long-running terminal work alive
across network drops or disconnects. Start a named session,
detach safely, reattach when you reconnect, enumerate sessions,
and terminate the session when the work is complete.
You are performing a long upgrade process on a remote server.
You cannot risk losing progress if your SSH session drops. Your
job is to use screen to run the work inside a
persistent terminal session, detach and reconnect cleanly, and
then close the session when finished.
Persistent session tooling is a baseline reliability skill for remote operations. It prevents interrupted upgrades, lost logs, and half-applied changes when connectivity is unstable.
screen session for long-running
work.
screen session with
-S.
Ctrl+a then d.
screen -r.
screen -ls.
screen -S <name> -X quit.
devsession.
screen -S devsession
Starting a named session makes it easy to target and reattach later. In real workflows, naming sessions after a task or change ticket reduces operator error.
Screen session 'devsession' started.
Ctrl+a then d
Detaching leaves the session running in the background. This is the key behavior that preserves work across disconnects.
Detached from 'devsession'.
screen -r devsession
Reattaching returns you to the exact shell state inside the session. This is how you resume long-running work after a reconnect or after stepping away.
Reattached to screen session.
screen -ls
Listing sessions is your inventory check. It confirms what is running, whether a session is attached or detached, and which name or ID you should target.
There is a screen on:
11234.devsession (Detached)
1 Socket in /run/screen/S-user.
screen -S devsession -X quit
Terminating a session explicitly avoids leaving “orphan” sessions behind. In real environments, stale sessions can confuse operators, waste resources, and hide unfinished work.
Session 'devsession' terminated.
screen -S <name>
: Starts a new named screen session.
-S
: Assigns a human-readable session name.
Ctrl+a
then
d
: Detaches from the current screen session without ending it.
screen -r <name>
: Reattaches to an existing session by name or ID.
screen -ls
to identify the correct target.
screen -ls
: Lists active screen sessions for the current user.
screen -S <name> -X quit
: Sends a command to a session to terminate it.
-X
: Executes a screen command in the target session.
quit
: Ends the session.