Skip to content
Home
Terminal Multiplexers: tmux and screen

Terminal Multiplexers: tmux and screen

Developer Tools Developer Tools 7 min read 1373 words Beginner ExcellentWiki Editorial Team

A terminal multiplexer lets you run multiple terminal sessions in a single window, detach and reattach to sessions remotely, and organize your work into windows and panes. tmux and GNU screen are the two dominant multiplexers on Linux and macOS.

tmux Basics

Sessions, Windows, and Panes

tmux
├── Session (e.g., "dev")
│   ├── Window 0: editor (e.g., vim)
│   │   ├── Pane 0: code
│   │   └── Pane 1: terminal
│   ├── Window 1: server
│   └── Window 2: logs
LevelDescriptiontmux command
SessionA collection of windowstmux new -s myname
WindowA full-screen workspacePrefix c (create)
PaneA split within a windowPrefix % (vertical), Prefix " (horizontal)

Essential Key Bindings

All tmux commands start with the prefix (default: Ctrl-b):

BindingAction
Prefix %Split pane vertically
Prefix "Split pane horizontally
Prefix arrowNavigate panes
Prefix cCreate new window
Prefix p / nPrevious / next window
Prefix 0-9Switch to window by number
Prefix dDetach from session
Prefix [Enter copy mode (scrollback)
Prefix :Enter command mode

Starting and Reattaching

# Start a named session
tmux new -s development

# Detach: Ctrl-b d

# List sessions
tmux ls

# Reattach to an existing session
tmux attach -t development

# Kill a session
tmux kill-session -t development

Session Management Flow

The typical development workflow with tmux:

  1. Start a session: tmux new -s project-x
  2. Create windows for editor, build, logs, and git
  3. Work across panes — split the editor window for code and test file side by side
  4. When you need to switch contexts or leave, detach: Prefix d
  5. SSH in from another machine and reattach: tmux attach -t project-x
  6. Everything is exactly where you left it — scrollback, split layout, cursor positions

tmux Configuration

Create ~/.tmux.conf to customize:

# Set prefix to Ctrl-a (like screen)
set -g prefix C-a
unbind C-b
bind C-a send-prefix

# Mouse support
set -g mouse on

# Increase scrollback buffer
set -g history-limit 50000

# Status bar customization
set -g status-bg black
set -g status-fg white
set -g status-left '#[fg=green]#S #[fg=white]|'
set -g status-right '#[fg=yellow]%Y-%m-%d %H:%M'

# Better pane navigation with vim keys
bind h select-pane -L
bind j select-pane -D
bind k select-pane -U
bind l select-pane -R

# Reload config
bind r source-file ~/.tmux.conf \; display-message "Config reloaded"

# Use vim keys for copy mode
setw -g mode-keys vi

tmux Plugins with TPM

# ~/.tmux.conf — install TPM
set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'tmux-plugins/tmux-sensible'
set -g @plugin 'tmux-plugins/tmux-resurrect'
set -g @plugin 'tmux-plugins/tmux-continuum'

run '~/.tmux/plugins/tpm/tpm'

# tmux-resurrect saves/restores sessions across reboots
set -g @resurrect-capture-pane-contents 'on'
# tmux-continuum auto-saves every 15 minutes
set -g @continuum-save-interval '15'

The tmux-resurrect plugin is transformative: it saves the entire tmux state — windows, panes, working directories, and even program state (if using restore-shell-program) — and restores it after a reboot. tmux-continuum adds automatic saving, making session persistence nearly transparent.

Additional Useful Plugins

PluginPurpose
tmux-yankSystem clipboard integration
tmux-prefix-highlightShows when prefix is active
tmux-batteryBattery status in status bar
tmux-cpuCPU usage in status bar
tmux-openOpen highlighted text in browser

GNU screen

Screen predates tmux and is available on virtually every Unix system. Its syntax and features overlap significantly with tmux but with some differences.

Screen Key Bindings

Prefix: Ctrl-a by default.

BindingAction
Prefix cCreate new window
Prefix SSplit horizontally
Prefix TabSwitch between regions
Prefix dDetach
Prefix ATitle the current window
Prefix escEnter copy/scrollback mode
# Start a screen session
screen -S mysession

# List sessions
screen -ls

# Reattach
screen -r mysession

Screen Configuration (~/.screenrc)

# Status line
hardstatus alwayslastline
hardstatus string '%{= kG}[ %{G}%H %{g}][%= %{=kw}%?%-Lw%?%{r}(%{W}%n*%f%t%?(%u)%?%{r})%{w}%?%+Lw%?%?%= %{g}][%{Y}%Y-%m-%d %{w}%c %{g}]'

# Scrollback buffer size
defscrollback 10000

# Start with a window named
screen -t shell 0

tmux vs screen

Featuretmuxscreen
LicenseBSDGPL
ConfigurationMore intuitiveMore cryptic syntax
Split panesNative, flexibleRegions (limited)
Copy modevim/emacs keysEmacs by default
256 color supportExcellentGood
Plugin ecosystemRich (TPM, resurrect, continuum)Minimal
Scriptablesend-keys, new-windowSimilar, less documented
Default prefixCtrl-bCtrl-a (conflicts with bash line editing)

tmux is the modern choice for new users. screen is valuable when you need something preinstalled on minimal systems or legacy servers.

Advanced tmux Workflows

Session Scripting

#!/bin/bash
# Automate a project setup
tmux new-session -d -s myproject
tmux rename-window -t myproject:0 'code'
tmux send-keys -t myproject:0 'cd ~/projects/myproject && vim' Enter
tmux new-window -t myproject:1 -n 'server'
tmux send-keys -t myproject:1 'cd ~/projects/myproject && npm run dev' Enter
tmux new-window -t myproject:2 -n 'git'
tmux send-keys -t myproject:2 'cd ~/projects/myproject && git status' Enter
tmux attach -t myproject

Pane Synchronization

# Toggle synchronized input across all panes
bind S setw synchronize-panes \; display "Sync toggled"

When synchronized, keystrokes in one pane are replicated to all panes in the same window — useful for running the same command across multiple servers.

Remote Session Attach

# From local machine, attach to a remote tmux session
ssh user@server -t 'tmux attach -t main || tmux new -s main'

The -t flag forces SSH to allocate a TTY, and the fallback creates the session if it does not exist. Combined with tmux-resurrect, this makes remote development nearly indistinguishable from local work.

Custom Key Bindings for Efficiency

# Faster pane resizing
bind -r H resize-pane -L 5
bind -r J resize-pane -D 5
bind -r K resize-pane -U 5
bind -r L resize-pane -R 5

# Quick session switching
bind Tab switch-client -l

The -r flag allows the key to be repeated without holding the prefix, making resize operations fluid and fast.

FAQ

What is the main advantage of tmux over GNU screen?

tmux offers a better configuration syntax, native vertical and horizontal pane splitting, a rich plugin ecosystem (TPM), superior 256-color and true-color support, and more active development. screen’s main advantage is its near-universal availability.

How do I scroll back in tmux?

Enter copy mode with Prefix [ (default Ctrl+b [). Use PageUp/PageDown to scroll, or vi keys (j/k). Press q to exit copy mode.

Can I share a tmux session with another user?

Yes. Use tmux new-session -s shared and then tmux attach -t shared from another terminal. For multi-user sessions, use tmux new-session -s shared -d and others attach with tmux attach -t shared. The tmux -S /tmp/shared socket option allows session sharing between different Unix users.

How do I make tmux use my system clipboard?

Install the tmux-yank plugin, which integrates with xclip (Linux) or pbcopy (macOS). With mode-keys vi, select text in copy mode and press y to yank to the system clipboard.

Why does my tmux status bar show the wrong time?

The status bar updates by default every 15 seconds. You can change this with set -g status-interval 5. If the time zone is wrong, set the TZ environment variable before starting tmux.


Related: See our SSH keys guide and VS Code shortcuts.

Tmux vs Screen: A Detailed Comparison

While both tmux and GNU Screen provide terminal multiplexing, their feature sets differ significantly. Tmux offers a client-server architecture where sessions survive even if the terminal emulator crashes — reattach with tmux attach. Tmux’s vi/emacs mode keybindings are more intuitive for developers familiar with those editors. The status bar in tmux is highly customizable via status-left, status-right, and status-interval options, displaying battery, time, hostname, and session list. Tmux supports 256 colors and true color (24-bit) out of the box, while Screen requires extensive configuration. Tmux’s copy mode integrates with the system clipboard: set -g set-clipboard on enables seamless copy-paste between tmux and GUI applications. Screen has a smaller feature set but lighter resource usage, making it preferable on minimal embedded systems. Both support split panes, session persistence, and scrollback buffers, but tmux’s -S socket flag enables multiple users to share a session for pair programming.

Advanced Tmux Workflows

Tmux plugins via tpm (Tmux Plugin Manager) extend functionality: tmux-resurrect restores all panes, windows, and running programs after a reboot; tmux-yank adds system-clipboard integration; tmux-cpu displays CPU and memory usage. Nested tmux sessions (SSH into a server running tmux) require prefix key differentiation. Synchronized panes (setw synchronize-panes) type the same input into multiple panes simultaneously for mass server administration. Tmux’s pipe-pane logs pane output to a file, creating an audit trail.

Section: Developer Tools 1373 words 7 min read Beginner 756 articles in section Report inaccuracy Back to top