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.
tmuxtmux new -s <name> — Start a new named session.
tmux new -s projecttmux ls — List all active sessions.
tmux lstmux attach -t <name> — Attach to an existing session by name or number.
tmux attach -t projecttmux attach — Attach to the most recently used session.
tmux attachtmux kill-session -t <name> — Kill a specific session.
tmux kill-session -t projecttmux kill-server — Kill the tmux server and all sessions.
tmux kill-servertmux rename-session -t <old> <new> — Rename an existing session.
tmux rename-session -t 0 maintmux switch -t <name> — Switch to a different session from within tmux.
tmux switch -t projectSession Key Bindings (Prefix: Ctrl+b)
Ctrl+b d — Detach from the current session (session keeps running in background).
Ctrl+b dCtrl+b $ — Rename the current session.
Ctrl+b $Ctrl+b s — Show session list and switch interactively.
Ctrl+b sCtrl+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 LWindows (Tabs)
Ctrl+b c — Create a new window.
Ctrl+b cCtrl+b , — Rename the current window.
Ctrl+b ,Ctrl+b w — List all windows and select interactively.
Ctrl+b wCtrl+b n — Switch to the next window.
Ctrl+b nCtrl+b p — Switch to the previous window.
Ctrl+b pCtrl+b <number> — Switch to window by number (0-9).
Ctrl+b 2Ctrl+b & — Close the current window (with confirmation).
Ctrl+b &Ctrl+b l — Toggle to the last active window.
Ctrl+b ltmux swap-window -s <src> -t <dst> — Swap two windows by their index numbers.
tmux swap-window -s 2 -t 0tmux move-window -t <index> — Move the current window to a new index.
tmux move-window -t 5Panes (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 oCtrl+b q — Show pane numbers briefly. Press a number to jump to that pane.
Ctrl+b qCtrl+b x — Close the current pane (with confirmation).
Ctrl+b xCtrl+b z — Toggle zoom on the current pane (fullscreen/restore).
Ctrl+b zCtrl+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 SpacePane 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 10tmux resize-pane -U <n> — Resize the current pane up by n rows.
tmux resize-pane -U 5tmux resize-pane -L <n> — Resize the current pane left by n columns.
tmux resize-pane -L 10tmux resize-pane -R <n> — Resize the current pane right by n columns.
tmux resize-pane -R 10Copy 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).
qSpace — Start selection (while in copy mode with vi keys).
SpaceEnter — Copy selection and exit copy mode (with vi keys).
EnterCtrl+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.txttmux capture-pane -p -S -<n> — Capture n lines of scrollback history.
tmux capture-pane -p -S -1000 > scrollback.txtCommand Mode & Miscellaneous
Ctrl+b : — Enter tmux command prompt (type any tmux command without the 'tmux' prefix).
Ctrl+b : split-window -hCtrl+b ? — Show all key bindings.
Ctrl+b ?Ctrl+b t — Show a large clock in the current pane.
Ctrl+b ttmux source-file ~/.tmux.conf — Reload the tmux configuration file.
tmux source-file ~/.tmux.conftmux info — Show tmux server information and terminal capabilities.
tmux infotmux list-keys — List all key bindings and their commands.
tmux list-keysConfiguration (~/.tmux.conf)
set -g mouse on — Enable mouse support for scrolling, pane selection, and resizing.
set -g mouse onset -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-prefixset -g base-index 1 — Start window numbering from 1 instead of 0.
set -g base-index 1
setw -g pane-base-index 1set -g history-limit <n> — Set the scrollback buffer size (number of lines).
set -g history-limit 50000setw -g mode-keys vi — Use vi-style key bindings in copy mode.
setw -g mode-keys viset -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