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 sessiontmux new -s mysession
Detach from sessionCtrl+B then d
List sessionstmux ls
Reattach to sessiontmux attach -t mysession
Split horizontallyCtrl+B then "
Split verticallyCtrl+B then %
Move between panesCtrl+B then arrow keys
New windowCtrl+B then c
Next/prev windowCtrl+B then n / p
Kill current paneCtrl+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:

  1. Start a named session: tmux new -s firmware
  2. Split vertically — editor on the left, serial monitor on the right
  3. Create a second window for git operations and builds
  4. Detach and go for lunch — your build keeps running
  5. 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.