I've been a long-time user of GNU Screen, and I've always recommended it to anyone working with remote servers. Screen is an excellent tool that's saved me countless times when SSH connections drop or I need to run long-running processes. But it has one major problem: it's tough to configure and learn.
Recently I discovered tmux, and I'm making the switch. If you're not familiar with terminal multiplexers or you're struggling with Screen's complexity, tmux might be exactly what you need.
What Are Terminal Multiplexers?
Terminal multiplexers let you run multiple terminal sessions inside a single window, and more importantly, they let sessions persist even when you disconnect. This is crucial for remote server work.
The typical scenario: you SSH into a server, start a long-running process, and your connection drops. Without a multiplexer, your process dies. With Screen or tmux, the session continues running on the server, and you can reconnect and pick up exactly where you left off.
Why tmux Over GNU Screen?
GNU Screen has been the standard for decades, and it's solid software. But it has rough edges:
- Confusing default keybindings –
Ctrl-aconflicts with bash line navigation - Cryptic configuration – The
.screenrcsyntax is arcane - Steep learning curve – Basic operations require memorizing obscure commands
- Limited split functionality – Splitting windows is awkward
tmux addresses all of these issues:
- Better default prefix –
Ctrl-bdoesn't conflict with anything - Cleaner configuration –
.tmux.confsyntax is more intuitive - Easier to learn – Logical keybindings that make sense
- Better splits – Vertical and horizontal splits work smoothly
- Active development – tmux is actively maintained with new features
Installation
On Mac with Homebrew:
$ brew install tmux
On Ubuntu/Debian:
$ sudo apt-get install tmux
On other systems, tmux is likely in your package manager as well.
Basic Usage
Start tmux:
$ tmux
That's it. You're now in a tmux session. The status bar at the bottom shows you're in session 0, window 0.
Essential keybindings (all start with Ctrl-b):
Ctrl-b c– Create new windowCtrl-b n– Next windowCtrl-b p– Previous windowCtrl-b d– Detach from sessionCtrl-b %– Split pane verticallyCtrl-b "– Split pane horizontallyCtrl-b arrow– Navigate between panes
Reattach to a session:
$ tmux attach
If you have multiple sessions, list them with tmux ls and attach to a specific one with tmux attach -t <session-name>.
Configuration
Create ~/.tmux.conf for your settings. Here's a useful starting configuration:
# Enable mouse support (helpful when starting out)
set -g mouse on
# Improve colors
set -g default-terminal "screen-256color"
# Set scrollback buffer
set -g history-limit 10000
# Start window numbering at 1 instead of 0
set -g base-index 1
After creating or editing .tmux.conf, reload it inside tmux with:
Ctrl-b :source-file ~/.tmux.conf
Practical Use Cases
Remote server management – SSH into a server, start tmux, run your processes. If your connection drops, just SSH back in and tmux attach.
Long-running tasks – Start a deployment, database migration, or backup inside tmux. Detach and do other work. Check back later.
Development workflow – One pane for your editor, one for running the app, one for logs, one for a shell. All visible at once.
Pair programming – Multiple users can attach to the same tmux session and see the same screen. Everyone sees what everyone else types in real-time.
Getting More Advanced
This should be enough to get you started. For a comprehensive keybinding reference, check out this tmux cheat sheet.
As you get comfortable, explore splitting panes, creating named sessions, customizing the status bar, and setting up complex layouts. tmux is powerful once you know the basics. Last modified: 2011-07-12 WordPress ID: 897