screen Command
Create and manage multiple terminal sessions within a single terminal window using the screen terminal multiplexer.
Syntax
The screen command allows you to run multiple terminal sessions, detach from them, and reattach later, making it ideal for long-running processes and remote work.
Common Options
| Option | Description |
|---|---|
-S name |
Create a new session with specified name |
-r [name] |
Reattach to a detached session |
-d |
Detach the session (force detach if attached elsewhere) |
-D |
Detach and logout remote session |
-list |
List all screen sessions |
-ls |
Same as -list |
-x |
Attach to session without detaching other users |
-R |
Reattach if possible, otherwise create new session |
-c file |
Use specified config file |
-m |
Force creation of new session |
Basic Usage
Starting and managing sessions
Create and list screen sessions
Detaching and reattaching
Detach from and reattach to screen sessions
Session management
Advanced session management operations
Screen Key Bindings
Essential key combinations (Ctrl+A prefix)
| Key Combination | Action |
|---|---|
Ctrl+A, D |
Detach from session |
Ctrl+A, C |
Create new window |
Ctrl+A, N |
Switch to next window |
Ctrl+A, P |
Switch to previous window |
Ctrl+A, 0-9 |
Switch to window number |
Ctrl+A, " |
List all windows |
Ctrl+A, A |
Rename current window |
Ctrl+A, K |
Kill current window |
Ctrl+A, S |
Split screen horizontally |
Ctrl+A, | |
Split screen vertically |
Ctrl+A, Tab |
Switch between split regions |
Ctrl+A, X |
Close current split region |
Ctrl+A, Q |
Close all split regions except current |
Ctrl+A, ? |
Show help (key bindings) |
Window Management
Creating and switching windows
Manage multiple windows within a screen session
Window naming and organization
Organize and name windows for better workflow
Screen Splitting
Horizontal and vertical splits
Split screen to view multiple windows simultaneously
Practical splitting workflow
Example workflow using screen splitting for development
Practical Examples
Long-running processes
Use screen for long-running processes that shouldn't be interrupted
Development environment
Set up a complete development environment with multiple windows
Remote server management
Manage remote servers with persistent screen sessions
Configuration
Screen configuration file (.screenrc)
Customize screen behavior with configuration file
Advanced configuration options
Advanced screen configuration for power users
Troubleshooting
Common Issues and Solutions
- Cannot reattach to session - Check if session exists with
screen -ls - Session appears attached elsewhere - Use
screen -d -r sessionnameto force reattach - Screen freezes - Press Ctrl+Q to unfreeze (Ctrl+S freezes)
- Cannot create new window - Check if you've reached the window limit
- Lost session after network disconnect - Sessions should persist; check with
screen -ls
Session recovery and cleanup
Recover and clean up screen sessions
Best Practices
Screen Usage Best Practices
- Always use named sessions for better organization
- Name your windows descriptively for easy identification
- Regularly clean up unused sessions with
screen -wipe - Use configuration file to customize key bindings and behavior
- Document your screen setup for team members
- Consider using tmux for more advanced features
Security Considerations
- Be careful with multi-user sessions and permissions
- Use password protection for sensitive sessions
- Regularly audit active sessions
- Avoid running privileged commands in shared sessions
- Log out properly to prevent session hijacking