GNU Screen
Traditional terminal multiplexer with decades of stability and reliability.
Official WebsiteFeatures
Installation
brew install screenapt install screenpacman -S screendnf install screenWhy Use GNU Screen?
GNU Screen is the oldest terminal multiplexer, with development continuing since 1987. Its strength lies in stability from years of proven use and portability, being pre-installed on nearly all Unix-like systems.
Long Track Record and Stability
With over 30 years of history, it's a stable software with bugs thoroughly fixed. Safe to use in production environments.
Wide Portability
Pre-installed by default on nearly all Linux distributions. Ready to use on any server immediately.
Session Sharing
Multiple users can share the same session. Convenient for pair programming and remote support.
Serial Connection Support
Device connection via serial port. Useful for embedded development and network equipment configuration.
Basic Usage
About the Prefix Key
All screen operations start with the prefix key. The default is Ctrl + a. When C-a is mentioned below, press Ctrl + a first, then the next key.
Example: C-a c = Press Ctrl + a, then press c
Starting and Exiting Screen
# Start screen
screen
# Start with a session name
screen -S mysession
# Exit screen (close all windows)
exit
# Or use C-a d to detach (keep the session alive)Session Management
Creating, Listing, and Switching Sessions
# Create a new session
screen -S project1
# List sessions
screen -ls
# Attach to an existing session
screen -r project1
# Attach to a detached session
screen -d -r project1
# Force detach and attach to an attached session
screen -D -r project1
# Kill a session
screen -X -S project1 quit
# Kill all sessions
killall screenDetach and Attach
# Detach from session (keep it alive)
# C-a d
# Attach to the last session
screen -r
# If multiple sessions exist, specify the name
screen -r project1
# Multi-attach (connect from multiple terminals)
screen -x project1Session Sharing
# Enable multi-user mode (write to .screenrc)
multiuser on
acladd username # Add allowed user
# Connect to another user's session
screen -x username/sessionname
# Connect read-only
screen -x -r username/sessionnameWindow and Pane Operations
Window Operations
# Create a new window
# C-a c
# Move to next window
# C-a n
# Move to previous window
# C-a p
# Move to window by number
# C-a 0-9
# Display window list
# C-a w
# Select from window list
# C-a "
# Rename current window
# C-a A
# Close current window
# C-a k
# or exitRegion Operations (Screen Splitting)
# Horizontal split (top/bottom)
# C-a S
# Vertical split (left/right)
# C-a |
# Move between regions
# C-a Tab
# Close current region
# C-a X
# Close all but current region
# C-a Q
# Resize region
# C-a :resize +5
# C-a :resize -5Command Line Operations
# Run command in specific session
screen -S mysession -X stuff "ls -la\n"
# Run command in specific window
screen -S mysession -p 0 -X stuff "echo hello\n"
# Select specific window
screen -S mysession -p 1 -X selectKey Bindings Reference
Default prefix key is Ctrl + a (C-a). Below is a list of the main keybindings.
| Category | Key | Description |
|---|---|---|
| Session | C-a d | Detach |
C-a D D | Detach and logout | |
| Window | C-a c | Create new window |
C-a n / p | Next/Previous window | |
C-a 0-9 | Move to window by number | |
C-a w | Display window list | |
C-a " | Window selection menu | |
C-a A | Rename window | |
C-a k | Kill window | |
| Region | C-a S | Horizontal split |
C-a | | Vertical split | |
C-a Tab | Move between regions | |
C-a X | Close current region | |
C-a Q | Close other regions | |
| Copy | C-a [ | Enter copy mode |
C-a ] | Paste | |
| Other | C-a ? | List keybindings |
C-a : | Command mode | |
C-a a | Send Ctrl+a | |
C-a H | Start/stop hardcopy log |
Configuration File
~/.screenrc
Write screen configuration in ~/.screenrc. After making changes, restart screen or press C-a : and run source ~/.screenrc.
# Hide startup message
startup_message off
# Scrollback buffer size
defscrollback 10000
# Visual bell (no beep)
vbell on
vbell_msg "Bell!"
# Default shell
shell -$SHELL
# Auto detach
autodetach on
# UTF-8 support
defutf8 on
# Status line (hardstatus)
hardstatus alwayslastline
hardstatus string '%{= kG}[ %{G}%H %{g}][%= %{= kw}%?%-Lw%?%{r}(%{W}%n*%f%t%?(%u)%?%{r})%{w}%?%+Lw%?%?%= %{g}][%{B} %m/%d %{W}%c %{g}]'
# Auto-update window title
shelltitle "$ |bash"
# Mouse scroll support
termcapinfo xterm* ti@:te@
# 256 color support
term screen-256color
# Change escape key (optional)
# escape ^Tt # Change to Ctrl+t
# Create default windows
screen -t main 0
screen -t work 1
screen -t logs 2
# Select first window
select 0
# Region layout
# layout autosave on
# layout new default
# Customize keybindings
bind j focus down
bind k focus up
bind h focus left
bind l focus right
# Resize
bind = resize =
bind + resize +1
bind - resize -1
# Split
bind | split -v
bind S split
# Preserve current directory in new windows
bind c screen 1
bind ^c screen 1Applying Configuration
# Restart screen to apply configuration
# Exit with exit, then start again
# Reload configuration inside screen
# Press C-a : then type
source ~/.screenrcTips
- •Press
C-a ato input Ctrl+a itself. Useful for bash line-beginning commands. - •Use
screen -xto connect to the same session from multiple terminals. Useful for pair programming and remote support. - •After region splitting, the new region doesn't have a window. Create a new one with
C-a c, or select a window withC-a ". - •Press
C-a Hto automatically log the session to a file. Useful for work records and debugging. - •Older servers may not have tmux installed, but screen is almost always available.
- •Serial connection is also possible, e.g.,
screen /dev/ttyUSB0 115200. Useful for embedded development and network equipment configuration. - •If you're familiar with tmux, byobu allows you to use screen with tmux-like keybindings.
Screen vs tmux Comparison
| Feature | screen | tmux |
|---|---|---|
| Prefix key | Ctrl+a | Ctrl+b |
| Portability | Pre-installed on most systems | Requires installation in most cases |
| Screen splitting | Regions (separate from windows) | Panes (intuitive) |
| Configuration flexibility | Standard | More flexible |
| Serial connection | Built-in support | Requires external tools |
| Multi-user | Built-in support | Possible but needs setup |
| Development status | Maintenance mode | Actively developed |