What Is tmux and Why Should You Care?
tmux is a terminal multiplexer — it lets you run multiple terminal sessions inside a single window, split your terminal into panes, and most importantly, detach and reattach to sessions. That last feature alone makes it indispensable for anyone who SSHes into remote machines.
Without tmux (or its older cousin screen), a dropped SSH connection kills everything running in that terminal. With tmux, your session keeps running on the server and you can reattach exactly where you left off.
Installation
# Debian/Ubuntu/Raspberry Pi OS
sudo apt install tmux
# Arch
sudo pacman -S tmux
# macOS (Homebrew)
brew install tmux
Core Concepts: Sessions, Windows, and Panes
tmux has a three-level hierarchy:
- Session — the top-level container. You can have multiple sessions (e.g., one per project).
- Window — like a tab in your terminal. A session can have many windows.
- Pane — a split within a window. A window can be divided into multiple panes.
The prefix key is the gateway to all tmux commands. The default is Ctrl+B. Press it, release it, then press a command key.
Essential Commands Reference
| Action | Shortcut |
|---|---|
| Start new session | tmux new -s mysession |
| Detach from session | Ctrl+B then d |
| List sessions | tmux ls |
| Reattach to session | tmux attach -t mysession |
| Split horizontally | Ctrl+B then " |
| Split vertically | Ctrl+B then % |
| Move between panes | Ctrl+B then arrow keys |
| New window | Ctrl+B then c |
| Next/prev window | Ctrl+B then n / p |
| Kill current pane | Ctrl+B then x |
| Zoom pane (toggle) | Ctrl+B then z |
A Typical Developer Workflow
Here's how a typical session might be organized for a firmware project:
- Start a named session:
tmux new -s firmware - Split vertically — editor on the left, serial monitor on the right
- Create a second window for
gitoperations and builds - Detach and go for lunch — your build keeps running
- Reattach from any terminal:
tmux attach -t firmware
Customizing tmux: The Config File
Create ~/.tmux.conf to make tmux feel like home. Here are the most useful tweaks:
# Change prefix to Ctrl+A (screen-style)
unbind C-b
set-option -g prefix C-a
bind-key C-a send-prefix
# Enable mouse support
set -g mouse on
# Start windows and panes at 1, not 0
set -g base-index 1
setw -g pane-base-index 1
# Increase scrollback buffer
set -g history-limit 10000
# Reload config without restart
bind r source-file ~/.tmux.conf \; display "Config reloaded!"
Copy Mode: Scrolling and Searching
Enter copy mode with Ctrl+B then [. Now you can scroll with arrow keys or Page Up/Down, and search backward with /. Press q to exit copy mode. This is invaluable for reviewing build output or log files without leaving your terminal.
tmux vs. screen
If you've used screen before, tmux offers a cleaner config, better multi-pane support, and active development. The learning curve is similar. Most developers who try tmux don't go back.