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.
Session 7
tmux new -s myworktmux lstmux attach -t myworktmux kill-session -t myworkCtrl+b dCtrl+b $tmux kill-serverWindow 6
Ctrl+b cCtrl+b ,Ctrl+b n / pCtrl+b 0-9Ctrl+b &Ctrl+b wPane 7
Ctrl+b %Ctrl+b "Ctrl+b arrowCtrl+b zCtrl+b xCtrl+b { / }Ctrl+b SpaceCopy Mode 5
Ctrl+b [qSpaceEnterCtrl+b ]Config ~/.tmux.conf 5
set -g mouse onset -g base-index 1setw -g mode-keys viset -g default-terminal "screen-256color"bind r source-file ~/.tmux.conf \; display "Reloaded!"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