What is tmux and Why Should You Use It?

If you spend significant time in the terminal, tmux (Terminal MUltipleXer) is one of those tools that fundamentally changes your workflow once you start using it. At its core, tmux lets you:

  • Run multiple terminal sessions inside a single window
  • Split your terminal into panes side-by-side or top-to-bottom
  • Detach from a session and reattach later — even from a different machine
  • Keep long-running processes alive when your SSH connection drops

Install it with: sudo apt install tmux

Core Concepts: Sessions, Windows, and Panes

Understanding the hierarchy is key:

  • Session — A collection of windows. You can detach and reattach to sessions. Think of a session as a project workspace.
  • Window — Like a tab in a browser. Each session can have multiple windows.
  • Pane — A split within a window. Each window can be divided into multiple panes, each running its own process.

Essential Keyboard Shortcuts

All tmux commands are prefixed with a prefix key — by default Ctrl+b. Press the prefix, release it, then press the command key.

ActionShortcut
New windowPrefix + c
Next windowPrefix + n
Previous windowPrefix + p
Split pane verticallyPrefix + %
Split pane horizontallyPrefix + "
Switch between panesPrefix + arrow keys
Detach sessionPrefix + d
List sessionsPrefix + s
Rename windowPrefix + ,
Kill current panePrefix + x

Named Sessions for Project-Based Workflows

Start named sessions to keep different projects organised:

tmux new -s webdev
tmux new -s sysadmin

Detach from a session with Prefix + d. List all sessions with tmux ls. Reattach to a specific session:

tmux attach -t webdev

Customising tmux with .tmux.conf

The default configuration is functional but not ideal. Create ~/.tmux.conf to personalise it. A recommended starter config:

# Change prefix to Ctrl+a (like GNU Screen)
unbind C-b
set-option -g prefix C-a
bind-key C-a send-prefix

# Enable mouse support
set -g mouse on

# Start window numbering at 1
set -g base-index 1

# Easier pane splitting
bind | split-window -h
bind - split-window -v

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

# Status bar
set -g status-style bg=colour235,fg=colour136
set -g status-right "%H:%M %d-%b-%y"

Apply changes without restarting: tmux source-file ~/.tmux.conf

Copy Mode: Scrolling and Selecting Text

Enter copy mode with Prefix + [. This lets you scroll back through terminal history using arrow keys or PgUp/PgDn. Press q to exit. Add this to your config to use vi-style keys in copy mode:

set-window-option -g mode-keys vi

tmux for Remote Work

One of tmux's killer use cases is SSH sessions. Start a tmux session on a remote server, then detach at will. Even if your connection drops, your work keeps running. When you reconnect:

ssh user@server
tmux attach

Everything is exactly where you left it. Running a long compile job, a server process, or a database migration? tmux keeps it alive.

tmux has a learning curve, but within a day or two it becomes indispensable. Start with sessions and pane splits, then gradually add customisations as your needs grow.