SSH disconnects. Terminal crashes. You lose your work and have to start over. tmux solves this by running persistent sessions that survive disconnections. Split your terminal into panes, manage multiple windows, and never lose your workspace again.
Session Persistence
Your terminal sessions keep running even when you disconnect. SSH into a server, start tmux, detach, and reconnect days later - everything is exactly where you left it.
Understanding tmux: Sessions, Windows, Panes
tmux organizes your workspace in a hierarchy. A session contains windows, and windows contain panes:
tmux hierarchy: Session "dev-project" with 3 windows, Window 1 active with 3 panes (editor, server, logs)
Key Features
Session Persistence
Sessions survive disconnections and reboots. Detach, go home, reattach - everything is still running.
Window/Pane Splits
Split your terminal horizontally and vertically. Run multiple commands side-by-side without switching tabs.
Detach/Attach
Leave processes running in the background. Reattach from any terminal, even over SSH.
Copy Mode
Scroll through terminal history, search text, and copy/paste with vim-like keybindings.
Practical Examples
Essential tmux workflows for daily use:
Installation
# macOS
brew install tmux
# Ubuntu/Debian
sudo apt install tmux
# Check version
tmux -V
Sessions: Create, Detach, Attach
# Start a new named session
tmux new -s myproject
# Detach from session (keeps running)
# Press: Ctrl+b then d
# List all sessions
tmux ls
# Attach to a session
tmux attach -t myproject
tmux a -t myproject # shorthand
# Kill a session
tmux kill-session -t myproject
Windows: Create and Navigate
# All commands start with prefix: Ctrl+b
# Create new window
Ctrl+b c
# Switch between windows
Ctrl+b 0 # go to window 0
Ctrl+b 1 # go to window 1
Ctrl+b n # next window
Ctrl+b p # previous window
# Rename current window
Ctrl+b ,
# List windows
Ctrl+b w
Panes: Split and Navigate
# Split horizontally (top/bottom)
Ctrl+b "
# Split vertically (left/right)
Ctrl+b %
# Navigate between panes
Ctrl+b arrow-keys
# Resize panes
Ctrl+b Ctrl+arrow-keys
# Zoom pane (toggle fullscreen)
Ctrl+b z
# Close current pane
Ctrl+b x # or just type 'exit'
Copy Mode (scroll and copy)
# Enter copy mode (scroll through history)
Ctrl+b [
# Navigate (vim-style)
j, k, h, l # or arrow keys
Ctrl+u, Ctrl+d # page up/down
# Search
/pattern # search forward
?pattern # search backward
n, N # next/previous match
# Select and copy
Space # start selection
Enter # copy selection
# Paste
Ctrl+b ]
# Exit copy mode
q
Why Developers Love It
- ✓ Never Lose Work - SSH disconnects? Terminal crashes? Your processes keep running in tmux.
- ✓ Perfect for Remote Work - Start a session on your server, detach, come back tomorrow - it's all there.
- ✓ Efficient Multitasking - Editor, server, logs, tests - all visible at once without switching tabs.
- ✓ Scriptable Layouts - Create scripts that set up your entire development environment with one command.
- ✓ Pair Programming - Multiple users can attach to the same session and see the same terminal.
Cheatsheet
Essential tmux commands (all start with prefix Ctrl+b):
| Shortcut | Action | Category |
|---|---|---|
Ctrl+b d |
Detach from session | Sessions |
Ctrl+b c |
Create new window | Windows |
Ctrl+b n / p |
Next / Previous window | Windows |
Ctrl+b 0-9 |
Switch to window N | Windows |
Ctrl+b % |
Split pane vertically | Panes |
Ctrl+b " |
Split pane horizontally | Panes |
Ctrl+b arrows |
Navigate panes | Panes |
Ctrl+b z |
Zoom pane (toggle) | Panes |
Ctrl+b x |
Close pane | Panes |
Ctrl+b [ |
Enter copy mode | Copy |
Ctrl+b ] |
Paste buffer | Copy |
Ctrl+b ? |
Show keybindings | Help |
Pro Tips
Advanced techniques and configurations for power users:
Remap Prefix to Ctrl+a
Many prefer Ctrl+a (like GNU Screen). Add to ~/.tmux.conf: unbind C-b; set -g prefix C-a; bind C-a send-prefix
Enable Mouse Support
Click to select panes and resize by dragging. Add to config: set -g mouse on
Use True Colors
For proper terminal colors: set -g default-terminal "tmux-256color" and set -ag terminal-overrides ",xterm-256color:RGB"
Quick Pane Navigation
Bind vim-style keys: bind h select-pane -L; bind j select-pane -D; bind k select-pane -U; bind l select-pane -R
Increase History Limit
Scroll back further: set -g history-limit 50000
Try a Plugin Manager
Install TPM for plugins like tmux-resurrect (save/restore sessions across restarts) and tmux-continuum (auto-save).
Getting Started
-
1
Install tmux
macOS:
brew install tmux| Ubuntu:sudo apt install tmux -
2
Create Your First Session
Run
tmux new -s devto start a named session -
3
Learn the Prefix
Press
Ctrl+b, then%to split. TryCtrl+b ?for help -
4
Detach and Reattach
Press
Ctrl+b dto detach, thentmux attachto come back
Never Lose Your Terminal Session Again
Install tmux and work with confidence. Your sessions persist through disconnects, crashes, and context switches.
Read the Wiki