tmux Cheatsheet - Terminal Multiplexer Command Reference

Running tmux on a server is insurance for your SSH session: the network drops, the laptop lid closes, you reconnect, and tmux attach puts everything back, with long-running jobs surviving a SIGHUP. The model has three levels — session, window, pane — and once that nesting is understood the key table becomes predictable: after Ctrl-b, c creates a window, n and p switch, % splits left and right, " splits top and bottom. The detail worth memorising is that tmux prefixes are composable: a bare prefix press is remembered, so e means expand-to-size — e then space fills the window, e then % splits it evenly. Copy mode is the second stumbling block: q to enter, arrows to select, Enter to copy — into tmux's own buffer rather than the system clipboard, unless you enable set-clipboard and the terminal cooperates. The configuration group covers remapping the prefix, mouse support, automatic window renaming and history depth. The screen comparison lives in the previous sheet: tmux wins on plugins and shareable sessions, and costs you an install first.

SysOps·30 commands·Last updated 2026-07-21
tmuxTerminalsshReuse

Session 7

tmux new -s mywork
Create a named session
tmux ls
List all sessions
tmux attach -t mywork
Attach to a specific session
tmux kill-session -t mywork
Kill a specific session
Ctrl+b d
Detach from current session (session keeps running)
Ctrl+b $
Rename current session
tmux kill-server
Kill all sessions and the tmux server

Window 6

Ctrl+b c
Create a new window
Ctrl+b ,
Rename current window
Ctrl+b n / p
Switch to next / previous window
Ctrl+b 0-9
Switch to window by number
Ctrl+b &
Close current window (confirms)
Ctrl+b w
Interactive window list selection

Pane 7

Ctrl+b %
Split pane horizontally
Ctrl+b "
Split pane vertically
Ctrl+b arrow
Move focus between panes
Ctrl+b z
Toggle pane zoom fullscreen/restore
Ctrl+b x
Close current pane (confirms)
Ctrl+b { / }
Swap pane positions
Ctrl+b Space
Cycle through layouts

Copy Mode 5

Ctrl+b [
Enter copy mode, scroll and select text
q
Exit copy mode
Space
Start selection (vi mode)
Enter
Copy selected text
Ctrl+b ]
Paste most recently copied text

Config ~/.tmux.conf 5

set -g mouse on
Enable mouse scrolling and pane dragging
set -g base-index 1
Start window numbering at 1 (default 0)
setw -g mode-keys vi
Use vi key bindings in copy mode
set -g default-terminal "screen-256color"
Enable 256 colors, fix display issues
bind r source-file ~/.tmux.conf \; display "Reloaded!"
Bind r to reload config

Command Examples

Create a session, work, detach, return

tmux new -s mywork # 干活中按 Ctrl+b 然后按 d 脱离 tmux attach -t mywork

脱离后会话在后台继续运行,长任务不会因为关掉终端而中断。这是 tmux 相对 screen 的最大优势——还有分屏、脚本化与更顺手的快捷键。

Output

[detached (attached from another client)]

A three-pane dev layout

# 启动后:Ctrl+b % 左右分屏;Ctrl+b " 上下分屏 tmux new -s dev # 左:编辑器 右上:tail 日志 右下:shell

用 Ctrl+b % 和 Ctrl+b " 组合出想要的布局,Ctrl+b 方向键切换焦点。也可以用 tmuxinator 之类的工具把布局写成配置文件一键恢复。

Enable mouse and 1-based indexing

# ~/.tmux.conf set -g mouse on set -g base-index 1 setw -g mode-keys vi bind r source-file ~/.tmux.conf \; display "Reloaded!"

mouse on 让滚轮能翻历史、拖拽可调窗格大小,不用记快捷键。改完配置按 Ctrl+b r 重载,无需重启会话。

Common Pitfalls

  • kill-session terminates every process and all unsaved work in that session — verify the session name first.
  • Jobs started inside tmux die with the session; run critical work under nohup or systemd instead.
  • Without mouse on you cannot scroll history with the wheel and must enter copy-mode.
  • Copy mode defaults to emacs keys; set mode-keys vi if you expect vi bindings or the keys will feel wrong.
  • tmux preserves the process and terminal state, not buffer contents — unsaved editor buffers are still lost.

Tips

  • tmux sessions survive SSH disconnects — reattach with tmux attach after reconnecting, essential for remote development.
  • Ctrl+b is the default prefix key — change it to Ctrl+a in .tmux.conf if it conflicts with terminal shortcuts.
  • Text selected in copy mode goes to the tmux buffer — extra configuration is needed to sync with the system clipboard.

Official References

Each command links to its official documentation below, so you can verify the latest usage and read deeper.

Maintained by LaoHand

Publicly updated on Jul 21, 2026, continuously proofread against official docs.

Contact Us

Wrong command or description? Send us corrections, business inquiries or product feedback by email.

Contact Us