Quick Reference Card

Action Command Notes
Start session screen Basic session
Start named session screen -S name Recommended!
Detach session Ctrl + A, then D Keep running!
List sessions screen -ls Show all active
Reattach session screen -r name Resume work
Kill session exit or screen -S name -X quit End session
Split horizontally Ctrl + A, then S Advanced
Switch between splits Ctrl + A, then Tab Advanced

What is Linux Screen?

When working on Linux servers, network disconnections can kill your running processes. The screen command creates persistent terminal sessions that survive disconnections, letting you pick up exactly where you left off.

Perfect for:

  • Long-running backups or file transfers
  • Compiling large codebases
  • System monitoring tasks
  • Any process that takes hours to complete

Installation

Most Linux distributions include screen by default. If missing:

Ubuntu/Debian:

sudo apt update && sudo apt install screen

CentOS/RHEL/Rocky:

sudo yum install screen
# or on newer versions:
sudo dnf install screen

Arch Linux:

sudo pacman -S screen

Verify installation:

screen --version

Essential Screen Commands

1. Starting Sessions

Basic session:

screen

Named session (recommended):

screen -S backup-job
screen -S database-migration  
screen -S monitoring

💡 Pro tip: Always name your sessions for easy identification!

2. The Magic Detach Command

Detach and keep running:

Ctrl + A, then D

This is the most important screen command. Your process continues running in the background.

3. Managing Sessions

List all active sessions:

screen -ls

Sample output:

There are screens on:
    15234.backup-job    (Detached)
    15891.monitoring    (Attached)
    16124.database-migration    (Detached)

Reattach to a session:

screen -r backup-job
screen -r 15234    # Using session ID also works

Force reattach (if session shows as Attached):

screen -r -d backup-job

4. Ending Sessions

Clean exit (from within the screen):

exit

Force kill a session:

screen -S backup-job -X quit

Kill all detached sessions:

screen -wipe

Real-World Examples

Example 1: Database Backup

# Start named session
screen -S db-backup

# Run your backup command
mysqldump -u root -p mydb > backup.sql

# Detach with Ctrl+A, D
# Check progress later with: screen -r db-backup

Example 2: File Synchronization

# Start session for long rsync job
screen -S sync-files

# Start the sync
rsync -avz --progress /local/data/ user@server:/remote/backup/

# Detach and come back later
# Reattach: screen -r sync-files

Example 3: System Monitoring

# Create monitoring session
screen -S monitoring

# Run continuous monitoring
htop
# or
tail -f /var/log/syslog

# Detach and let it run

Advanced Tips

Multiple Windows in One Session

# Create new window: Ctrl + A, then C  
# Switch windows: Ctrl + A, then N (next) or P (previous)
# List windows: Ctrl + A, then W

Split Screen View

# Horizontal split: Ctrl + A, then S
# Vertical split: Ctrl + A, then |  
# Switch splits: Ctrl + A, then Tab
# Close split: Ctrl + A, then X

Session Logging

# Start session with logging
screen -L -S logged-session

# Log file saved as: screenlog.0

Troubleshooting

Problem: Can't reattach - session shows as "Attached"
Solution:

screen -r -d session-name  # Force detach and reattach

Problem: Lost session names
Solution:

screen -ls  # Lists all sessions with IDs
screen -r [session-id]  # Reattach using ID number

Problem: Too many dead sessions
Solution:

screen -wipe  # Cleans up dead sessions

Screen vs Alternatives

Tool Best For Pros Cons
screen Simple persistent sessions Lightweight, universal Basic features
tmux Advanced terminal multiplexing More features, better splits Steeper learning curve
nohup One-off background jobs Simple for single commands No interaction

Why Screen Matters for System Administrators

In production environments, screen is essential because:

  • Reliability: Critical processes don't die with your SSH session
  • Monitoring: You can check long-running jobs anytime
  • Collaboration: Multiple users can attach to the same session
  • Debugging: Easily access logs and outputs from persistent sessions

Quick Start Workflow

  1. SSH to your server
  2. Start named screen: screen -S my-task
  3. Run your command
  4. Detach: Ctrl + A, D
  5. Disconnect from server (process keeps running!)
  6. Later: SSH back and reattach: screen -r my-task

That's it! You've mastered the essential skill that separates casual Linux users from professionals.

Conclusion

Master these screen basics and you'll never lose work to dropped connections again. The screen command is a fundamental tool for anyone working with Linux servers, remote development, or long-running processes.

Remember the golden rule: Always detach (Ctrl + A, D) instead of closing your terminal!