tmux — Manage Multiple Terminal Sessions in One Window

Practical guide to tmux: start sessions, split windows and panes, detach and reattach – terminal sessions survive SSH drops and logout.

tmux is a terminal multiplexer: it bundles multiple terminal sessions, windows and panes into a single window – and keeps them alive even after you disconnect. That is exactly what makes it indispensable on remote servers: an SSH connection may drop or you may log out, yet your running processes keep working undisturbed in the detached session. This guide walks you through the commands and key bindings you actually reach for daily, from creating named sessions to your own ~/.tmux.conf.

Sessions

tmux — Start a new unnamed session.

tmux

tmux new -s <name> — Start a new named session.

tmux new -s project

tmux ls — List all active sessions.

tmux ls

tmux attach -t <name> — Attach to an existing session by name or number.

tmux attach -t project

tmux attach — Attach to the most recently used session.

tmux attach

tmux kill-session -t <name> — Kill a specific session.

tmux kill-session -t project

tmux kill-server — Kill the tmux server and all sessions.

tmux kill-server

tmux rename-session -t <old> <new> — Rename an existing session.

tmux rename-session -t 0 main

tmux switch -t <name> — Switch to a different session from within tmux.

tmux switch -t project

Session Key Bindings (Prefix: Ctrl+b)

Ctrl+b d — Detach from the current session (session keeps running in background).

Ctrl+b d

Ctrl+b $ — Rename the current session.

Ctrl+b $

Ctrl+b s — Show session list and switch interactively.

Ctrl+b s

Ctrl+b ( — Switch to the previous session.

Ctrl+b (

Ctrl+b ) — Switch to the next session.

Ctrl+b )

Ctrl+b L — Switch to the last (most recently used) session.

Ctrl+b L

Windows (Tabs)

Ctrl+b c — Create a new window.

Ctrl+b c

Ctrl+b , — Rename the current window.

Ctrl+b ,

Ctrl+b w — List all windows and select interactively.

Ctrl+b w

Ctrl+b n — Switch to the next window.

Ctrl+b n

Ctrl+b p — Switch to the previous window.

Ctrl+b p

Ctrl+b <number> — Switch to window by number (0-9).

Ctrl+b 2

Ctrl+b & — Close the current window (with confirmation).

Ctrl+b &

Ctrl+b l — Toggle to the last active window.

Ctrl+b l

tmux swap-window -s <src> -t <dst> — Swap two windows by their index numbers.

tmux swap-window -s 2 -t 0

tmux move-window -t <index> — Move the current window to a new index.

tmux move-window -t 5

Panes (Splits)

Ctrl+b % — Split the current pane vertically (left/right).

Ctrl+b %

Ctrl+b " — Split the current pane horizontally (top/bottom).

Ctrl+b "

Ctrl+b <arrow> — Move focus to the pane in the arrow direction.

Ctrl+b

Ctrl+b o — Cycle through panes in the current window.

Ctrl+b o

Ctrl+b q — Show pane numbers briefly. Press a number to jump to that pane.

Ctrl+b q

Ctrl+b x — Close the current pane (with confirmation).

Ctrl+b x

Ctrl+b z — Toggle zoom on the current pane (fullscreen/restore).

Ctrl+b z

Ctrl+b { — Swap the current pane with the previous one.

Ctrl+b {

Ctrl+b } — Swap the current pane with the next one.

Ctrl+b }

Ctrl+b Space — Cycle through preset pane layouts (even-horizontal, even-vertical, etc.).

Ctrl+b Space

Pane Resizing

Ctrl+b Ctrl+<arrow> — Resize the current pane by 1 cell in the arrow direction.

Ctrl+b Ctrl+→

Ctrl+b Alt+<arrow> — Resize the current pane by 5 cells in the arrow direction.

Ctrl+b Alt+→

tmux resize-pane -D <n> — Resize the current pane down by n rows.

tmux resize-pane -D 10

tmux resize-pane -U <n> — Resize the current pane up by n rows.

tmux resize-pane -U 5

tmux resize-pane -L <n> — Resize the current pane left by n columns.

tmux resize-pane -L 10

tmux resize-pane -R <n> — Resize the current pane right by n columns.

tmux resize-pane -R 10

Copy Mode & Scrollback

Ctrl+b [ — Enter copy mode to scroll and select text. Use arrow keys or Page Up/Down.

Ctrl+b [

q — Exit copy mode (while in copy mode).

q

Space — Start selection (while in copy mode with vi keys).

Space

Enter — Copy selection and exit copy mode (with vi keys).

Enter

Ctrl+b ] — Paste the most recently copied text.

Ctrl+b ]

tmux capture-pane -p — Capture the visible pane contents and print to stdout.

tmux capture-pane -p > output.txt

tmux capture-pane -p -S -<n> — Capture n lines of scrollback history.

tmux capture-pane -p -S -1000 > scrollback.txt

Command Mode & Miscellaneous

Ctrl+b : — Enter tmux command prompt (type any tmux command without the 'tmux' prefix).

Ctrl+b : split-window -h

Ctrl+b ? — Show all key bindings.

Ctrl+b ?

Ctrl+b t — Show a large clock in the current pane.

Ctrl+b t

tmux source-file ~/.tmux.conf — Reload the tmux configuration file.

tmux source-file ~/.tmux.conf

tmux info — Show tmux server information and terminal capabilities.

tmux info

tmux list-keys — List all key bindings and their commands.

tmux list-keys

Configuration (~/.tmux.conf)

set -g mouse on — Enable mouse support for scrolling, pane selection, and resizing.

set -g mouse on

set -g prefix C-a — Change the prefix key from Ctrl+b to Ctrl+a.

set -g prefix C-a
unbind C-b
bind C-a send-prefix

set -g base-index 1 — Start window numbering from 1 instead of 0.

set -g base-index 1
setw -g pane-base-index 1

set -g history-limit <n> — Set the scrollback buffer size (number of lines).

set -g history-limit 50000

setw -g mode-keys vi — Use vi-style key bindings in copy mode.

setw -g mode-keys vi

set -g default-terminal "screen-256color" — Set the default terminal type for 256-color support.

set -g default-terminal "screen-256color"

bind | split-window -h — Bind a custom key for splitting panes (e.g., | for vertical, - for horizontal).

bind | split-window -h
bind - split-window -v

Conclusion

tmux turns a single terminal into a full-blown workspace: tmux new -s <name> starts a named session, Ctrl+b d detaches you, and tmux attach -t <name> drops you back in exactly where you left off – even after an SSH drop or a logout. This persistence is what sets it apart from a plain terminal and makes it the modern, more powerful alternative to screen. For one-off background jobs without an interactive interface, nohup is often enough – but as soon as you need multiple windows, panes and a detachable session, tmux is the tool of choice. Prefix, mouse support and custom key bindings are configured permanently in ~/.tmux.conf.

Further Reading

  • tmux Wiki on GitHub – the official wiki with a getting-started guide, key bindings and configuration
  • Arch Wiki: tmux – detailed reference for configuration and practical tips
  • screen – the classic terminal multiplexer, predecessor and alternative to tmux
  • nohup – detach processes from the terminal so they survive logout and SSH drops
  • bash – the shell that runs inside every tmux pane