Terminal GuideTerminal Guide
screen icon

GNU Screen

Multiplexers
macOSLinux
C

Traditional terminal multiplexer with decades of stability and reliability.

Official Website

Features

Session ManagementWindow SplittingDetach/AttachSerial Console

Installation

Homebrew
brew install screen
APT (Debian/Ubuntu)
apt install screen
Pacman (Arch)
pacman -S screen
DNF (Fedora)
dnf install screen

Why 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

Basic Commands
# 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

Session Management
# 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 screen

Detach and Attach

Detach & 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 project1

Session Sharing

Session 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/sessionname

Window and Pane Operations

Window 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 exit

Region Operations (Screen Splitting)

Region Operations
# 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 -5

Command Line Operations

Command Line
# 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 select

Key Bindings Reference

Default prefix key is Ctrl + a (C-a). Below is a list of the main keybindings.

CategoryKeyDescription
SessionC-a dDetach
C-a D DDetach and logout
WindowC-a cCreate new window
C-a n / pNext/Previous window
C-a 0-9Move to window by number
C-a wDisplay window list
C-a "Window selection menu
C-a ARename window
C-a kKill window
RegionC-a SHorizontal split
C-a |Vertical split
C-a TabMove between regions
C-a XClose current region
C-a QClose other regions
CopyC-a [Enter copy mode
C-a ]Paste
OtherC-a ?List keybindings
C-a :Command mode
C-a aSend Ctrl+a
C-a HStart/stop hardcopy log

Configuration File

~/.screenrc

Write screen configuration in ~/.screenrc. After making changes, restart screen or press C-a : and run source ~/.screenrc.

~/.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 1

Applying Configuration

Apply Config
# Restart screen to apply configuration
# Exit with exit, then start again

# Reload configuration inside screen
# Press C-a : then type
source ~/.screenrc

Tips

  • Press C-a a to input Ctrl+a itself. Useful for bash line-beginning commands.
  • Use screen -x to 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 with C-a ".
  • Press C-a H to 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

Featurescreentmux
Prefix keyCtrl+aCtrl+b
PortabilityPre-installed on most systemsRequires installation in most cases
Screen splittingRegions (separate from windows)Panes (intuitive)
Configuration flexibilityStandardMore flexible
Serial connectionBuilt-in supportRequires external tools
Multi-userBuilt-in supportPossible but needs setup
Development statusMaintenance modeActively developed
Written by Dai AokiPublished: 2026-01-20

Related Articles

Explore More