Example 1
Start a New Screen Session
$ screen
Creates a new screen session with a default name. You'll see a new terminal window within screen. This session will persist even if you disconnect from SSH, allowing long-running processes to continue.
Key Command: Press Ctrl+A then D to detach from the session
Example 2
Start a Named Screen Session
$ screen -S session_name
Creates a new screen session with a custom name using the '-S' option. Named sessions are much easier to identify and reattach to later, especially when managing multiple screen sessions simultaneously.
Best Practice: Always name your sessions descriptively (e.g., 'backup', 'webserver', 'database')
Example 3
List All Screen Sessions
$ screen -ls
There are screens on:
12345.pts-0.hostname (Detached)
67890.webserver (Detached)
24680.backup (Attached)
3 Sockets in /var/run/screen/S-username.
12345.pts-0.hostname (Detached)
67890.webserver (Detached)
24680.backup (Attached)
3 Sockets in /var/run/screen/S-username.
Displays all active screen sessions with their IDs, names, and status (Attached or Detached). Essential for managing multiple sessions and finding the session you want to reconnect to.
Status: 'Attached' means actively connected, 'Detached' means running in background
Example 4
Reattach to a Detached Session
$ screen -r session_name
Reattaches to a previously detached screen session using the '-r' (resume) option. You can use either the session name or PID. All your running processes will be exactly as you left them.
Example: screen -r 12345 or screen -r webserver
Example 5
Detach from Current Session
Ctrl+A then D
Detaches from the current screen session while keeping it running in the background. This is the most common screen command. Press Ctrl+A (the command prefix), release, then press D. Your session continues running and you can reattach later.
Remember: All screen commands start with Ctrl+A prefix
Example 6
Create Multiple Windows in a Session
Ctrl+A then C
Creates a new window within the current screen session. Think of windows as tabs - you can have multiple terminal windows in one session. Use this to run different tasks in the same session without creating multiple sessions.
Navigation: Ctrl+A then N (next window), Ctrl+A then P (previous window)
Example 7
List All Windows in Current Session
Ctrl+A then "
Num Name Flags
0 bash $
1 top $
2 tail -f /var/log/syslog $
0 bash $
1 top $
2 tail -f /var/log/syslog $
Displays all windows in the current screen session by pressing Ctrl+A then the double-quote key. Shows window numbers, names, and what's running. Use arrow keys to select a window and press Enter to switch to it.
Direct Switch: Ctrl+A then [0-9] to jump to specific window number
Example 8
Split Screen Horizontally
Ctrl+A then S
Splits the current window horizontally into two regions, allowing you to view multiple windows simultaneously. After splitting, use Ctrl+A then Tab to move between regions, and Ctrl+A then C to create a new window in the active region.
Vertical Split: Ctrl+A then | (pipe symbol) for vertical split
Example 9
Kill a Screen Session
$ screen -X -S session_name quit
Terminates a screen session completely, closing all windows and stopping all processes within it. The '-X' option sends a command to a session, and 'quit' terminates it. Use this to clean up old sessions you no longer need.
Alternative: From within a session, type 'exit' in all windows or use Ctrl+A then K (kill window)
Example 10
Start Session with Logging Enabled
$ screen -L -S logged_session
Starts a new screen session with automatic logging enabled using the '-L' option. All terminal output is saved to a log file (screenlog.0 by default). Extremely useful for debugging, auditing, or keeping records of important operations.
Toggle Logging: Ctrl+A then H to turn logging on/off in existing session
Bonus
Essential Screen Key Commands Quick Reference
Ctrl+A then D - Detach from session
Ctrl+A then C - Create new window
Ctrl+A then N - Next window
Ctrl+A then P - Previous window
Ctrl+A then K - Kill current window
Ctrl+A then [ - Enter copy/scrollback mode
Ctrl+A then ] - Paste copied text
Ctrl+A then ? - Display help screen
Ctrl+A then A - Rename current window
Ctrl+A then X - Lock screen session
Ctrl+A then C - Create new window
Ctrl+A then N - Next window
Ctrl+A then P - Previous window
Ctrl+A then K - Kill current window
Ctrl+A then [ - Enter copy/scrollback mode
Ctrl+A then ] - Paste copied text
Ctrl+A then ? - Display help screen
Ctrl+A then A - Rename current window
Ctrl+A then X - Lock screen session
A quick reference of the most commonly used screen keyboard shortcuts. Remember, all commands start with the Ctrl+A prefix, release those keys, then press the command key.