--- title: screen โ€” session persistence (traditional tool) date: 2026-10-18 time: 12:00 model: admin category: programs author_type: human summary: A session persistence tool used before tmux. Still used because many environments have it installed by default. tags: program, Remote server connection management, screen --- **๐Ÿ’ฌ "screen command"** screen is a **session persistence tool** with the same purpose as tmux. It is often installed by default on older servers. The prefix key is Ctrl+a, followed by a key combination. - **Concept**: You can create terminal sessions and detach or reconnect to them. - **Prefix key**: Press Ctrl+a followed by a command key. - **Detach/reattach**: Detach with Ctrl+a d and reattach with screen -r. - **List**: View the session list with screen -ls. ## Common options | Option | Description | | --- | --- | | -S | Creates a named session | | -r | Reconnects to a session | | -ls | Displays the session list | | -dmS | Starts a session detached | ## Three essential command combinations - `screen -S deploy` โ€” Create a deploy session - `screen -ls` โ€” Check the session list - `screen -dmS batch bash -lc '/opt/app/bin/batch.sh'` โ€” Run a batch job in a detached session **๐Ÿ’ฌ "Show me examples of the most commonly used combinations in practice"** The following is a step-by-step summary of situations commonly encountered on production servers. ### Step 1 ยท Create a session Create a session for your work. ``` screen -S deploy ``` ### Step 2 ยท Run the task Run the long-running task inside the session. ``` ./bin/deploy.sh 2>&1 | tee /tmp/deploy.log ``` ### Step 3 ยท Detach/reconnect Exit with Ctrl+a d and reconnect. ``` screen -r deploy ``` ## How this is used in practice ### 1. Long-running work in a default installation environment **Situation** โ€” A server where tmux is not installed and only screen is available. ``` screen -dmS deploy bash -lc 'cd /opt/app && ./bin/deploy.sh > /tmp/deploy.log 2>&1' ``` **Result** โ€” The session runs the deployment in the background. **Point** โ€” Write the output to a file so you can check it without reconnecting. ### 2. Session cleanup **Situation** โ€” Old screen sessions have accumulated. ``` screen -ls ``` **Result** โ€” The list appears with (Detached)/(Attached) statuses. **Point** โ€” Sessions left Attached may be in use by someone, so do not kill them without checking. ## Important notes - The prefix key differs from tmux, so it is easy to confuse them (Ctrl+a). - Forcefully detaching an Attached session with -d can affect another user's work. - Sessions disappear when the server reboots. ## Actual output This is the result of checking the detached screen session list. ![screen command output: session list](https://games.aidebatehub.com/assets/screen-demo.png) Production server --- Source (HTML): https://games.aidebatehub.com/programs/linux/remote/screen.html This file is an auto-generated Markdown twin of the DevHub document.