tmux

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

tmux

tmux

Complete tmux management for terminal multiplexing.
针对终端复用的完整tmux管理指南。

Core Concepts

核心概念

┌─────────────────────────────────────────────────────────────┐
│ SERVER (one per socket)                                     │
│  ┌───────────────────────────────────────────────────────┐  │
│  │ SESSION ($0, $1, ...)                                 │  │
│  │  ┌─────────────────┐  ┌─────────────────┐            │  │
│  │  │ WINDOW (@0)     │  │ WINDOW (@1)     │  ...       │  │
│  │  │  ┌────┬────┐   │  │  ┌────────────┐ │            │  │
│  │  │  │PANE│PANE│   │  │  │   PANE     │ │            │  │
│  │  │  │ %0 │ %1 │   │  │  │    %2      │ │            │  │
│  │  │  └────┴────┘   │  │  └────────────┘ │            │  │
│  │  └─────────────────┘  └─────────────────┘            │  │
│  └───────────────────────────────────────────────────────┘  │
└─────────────────────────────────────────────────────────────┘
  • Server: Background process managing all state
  • Session (
    $id
    ): Named container of windows, persists after detach
  • Window (
    @id
    ): Tab-like container of panes within a session
  • Pane (
    %id
    ): Individual terminal within a window
  • Client: Terminal attached to a session
┌─────────────────────────────────────────────────────────────┐
│ SERVER (one per socket)                                     │
│  ┌───────────────────────────────────────────────────────┐  │
│  │ SESSION ($0, $1, ...)                                 │  │
│  │  ┌─────────────────┐  ┌─────────────────┐            │  │
│  │  │ WINDOW (@0)     │  │ WINDOW (@1)     │  ...       │  │
│  │  │  ┌────┬────┐   │  │  ┌────────────┐ │            │  │
│  │  │  │PANE│PANE│   │  │  │   PANE     │ │            │  │
│  │  │  │ %0 │ %1 │   │  │  │    %2      │ │            │  │
│  │  │  └────┴────┘   │  │  └────────────┘ │            │  │
│  │  └─────────────────┘  └─────────────────┘            │  │
│  └───────────────────────────────────────────────────────┘  │
└─────────────────────────────────────────────────────────────┘
  • Server(服务器): 管理所有状态的后台进程
  • Session(会话) (
    $id
    ): 命名的窗口容器,断开连接后仍会保留
  • Window(窗口) (
    @id
    ): 会话内类似标签页的窗格容器
  • Pane(窗格) (
    %id
    ): 窗口内的独立终端实例
  • Client(客户端): 连接到会话的终端

Router

指令路由

User saysLoad referenceDo
list sessions / status
references/session-management.md
inspect sessions
new session / create session
references/session-management.md
create session
attach / detach
references/session-management.md
attach/detach
kill session
references/session-management.md
terminate session
new window / create window
references/window-management.md
create window
rename window
references/window-management.md
rename window
kill window / close window
references/window-management.md
close window
switch window
references/window-management.md
navigate windows
split / new pane
references/pane-management.md
split pane
resize pane
references/pane-management.md
resize pane
move pane / swap pane
references/pane-management.md
rearrange panes
kill pane / close pane
references/pane-management.md
close pane
layout
references/layouts.md
apply/manage layouts
copy / paste / buffer
references/copy-mode.md
copy mode operations
config / tmux.conf / settings
references/configuration.md
configure tmux
keybind / bind / unbind
references/keybindings.md
key bindings
script / automate / send-keys
references/scripting.md
scripting/automation
capture / log / output
references/scripting.md
capture pane content
help / keys / cheatsheetinlineshow key reference
用户指令加载参考文档执行操作
列出会话/查看状态
references/session-management.md
检查会话状态
新建会话/创建会话
references/session-management.md
创建会话
连接/断开
references/session-management.md
连接/断开会话
删除会话
references/session-management.md
终止会话
新建窗口/创建窗口
references/window-management.md
创建窗口
重命名窗口
references/window-management.md
重命名窗口
删除窗口/关闭窗口
references/window-management.md
关闭窗口
切换窗口
references/window-management.md
切换窗口
拆分/新建窗格
references/pane-management.md
拆分窗格
调整窗格大小
references/pane-management.md
调整窗格尺寸
移动窗格/交换窗格
references/pane-management.md
重新排列窗格
删除窗格/关闭窗格
references/pane-management.md
关闭窗格
布局
references/layouts.md
应用/管理布局
复制/粘贴/缓冲区
references/copy-mode.md
复制模式操作
配置/tmux.conf/设置
references/configuration.md
配置tmux
快捷键绑定/绑定/解绑
references/keybindings.md
快捷键绑定设置
脚本/自动化/send-keys
references/scripting.md
脚本编写与自动化
捕获/日志/输出
references/scripting.md
捕获窗格内容
帮助/快捷键/速查表内置显示快捷键参考

Default Key Bindings (Prefix:
C-b
)

默认快捷键(前缀:
C-b

Session

会话管理

KeyAction
d
Detach from session
s
List/switch sessions
$
Rename session
(
/
)
Previous/next session
快捷键操作
d
断开当前会话
s
列出/切换会话
$
重命名会话
(
/
)
切换到上一个/下一个会话

Window

窗口管理

KeyAction
c
Create window
&
Kill window (confirm)
,
Rename window
0-9
Switch to window N
n
/
p
Next/previous window
l
Last window
w
List windows
f
Find window
快捷键操作
c
创建新窗口
&
删除窗口(需确认)
,
重命名当前窗口
0-9
切换到第N个窗口
n
/
p
切换到下一个/上一个窗口
l
切换到上一次使用的窗口
w
列出所有窗口
f
查找窗口

Pane

窗格管理

KeyAction
%
Split horizontally (left/right)
"
Split vertically (top/bottom)
x
Kill pane (confirm)
o
Cycle panes
q
Show pane numbers
z
Toggle zoom
{
/
}
Swap pane left/right
!
Break pane to window
ArrowsNavigate panes
Space
Cycle layouts
C-o
Rotate panes
快捷键操作
%
水平拆分窗格(左右布局)
"
垂直拆分窗格(上下布局)
x
删除窗格(需确认)
o
循环切换窗格
q
显示窗格编号
z
切换窗格全屏状态
{
/
}
向左/向右交换窗格
!
将当前窗格独立为新窗口
方向键切换到对应方向的窗格
Space
循环切换布局
C-o
旋转窗格位置

Copy Mode

复制模式

KeyAction
[
Enter copy mode
]
Paste buffer
=
Choose paste buffer
#
List buffers
快捷键操作
[
进入复制模式
]
粘贴缓冲区内容
=
选择要粘贴的缓冲区
#
列出所有缓冲区

Quick Reference

快速参考命令

bash
undefined
bash
undefined

Session

会话管理

tmux new -s name # Create named session tmux attach -t name # Attach to session tmux ls # List sessions tmux kill-session -t name # Kill session
tmux new -s name # 创建命名会话 tmux attach -t name # 连接到指定会话 tmux ls # 列出所有会话 tmux kill-session -t name # 删除指定会话

Window

窗口管理

tmux new-window -n name # Create named window tmux select-window -t :N # Go to window N tmux rename-window name # Rename current window
tmux new-window -n name # 创建命名窗口 tmux select-window -t :N # 切换到第N个窗口 tmux rename-window name # 重命名当前窗口

Pane

窗格管理

tmux split-window -h # Split horizontal tmux split-window -v # Split vertical tmux select-pane -t :.N # Go to pane N tmux resize-pane -D 5 # Resize down 5 lines
tmux split-window -h # 水平拆分窗格 tmux split-window -v # 垂直拆分窗格 tmux select-pane -t :.N # 切换到当前窗口的第N个窗格 tmux resize-pane -D 5 # 将窗格向下调整5行

Info

信息查询

tmux list-keys # All key bindings tmux info # Server info
undefined
tmux list-keys # 列出所有快捷键绑定 tmux info # 查看服务器信息
undefined

Safety Rules

安全规则

  • Confirm before kill: Always confirm before
    kill-session
    ,
    kill-window
    ,
    kill-pane
  • Check attachments: Before killing, check if session has active clients
  • Preserve work: Warn if panes have running processes
  • Config backup: Before editing
    ~/.tmux.conf
    , suggest backup
  • 删除前确认: 执行
    kill-session
    kill-window
    kill-pane
    前必须确认
  • 检查连接状态: 删除前检查会话是否有活跃客户端
  • 保护工作进程: 若窗格中有运行中的进程需发出警告
  • 配置文件备份: 编辑
    ~/.tmux.conf
    前建议先备份

Confirmation Policy

确认策略

Read-only (always OK):
  • tmux ls
    ,
    list-sessions
    ,
    list-windows
    ,
    list-panes
  • tmux info
    ,
    show-options
    ,
    display-message
  • tmux list-keys
    ,
    list-buffers
Requires confirmation:
  • kill-session
    ,
    kill-window
    ,
    kill-pane
  • kill-server
  • Editing
    ~/.tmux.conf
  • send-keys
    to panes (can affect running processes)
只读操作(无需确认):
  • tmux ls
    ,
    list-sessions
    ,
    list-windows
    ,
    list-panes
  • tmux info
    ,
    show-options
    ,
    display-message
  • tmux list-keys
    ,
    list-buffers
需要确认的操作:
  • kill-session
    ,
    kill-window
    ,
    kill-pane
  • kill-server
  • 编辑
    ~/.tmux.conf
  • 向窗格发送
    send-keys
    指令(可能影响运行中的进程)

Environment Variables

环境变量

VariableDescription
TMUX
Socket path (set inside tmux)
TMUX_PANE
Current pane ID
Check if inside tmux:
[ -n "$TMUX" ]
变量名说明
TMUX
Socket路径(在tmux内自动设置)
TMUX_PANE
当前窗格ID
检查是否处于tmux环境:
[ -n "$TMUX" ]

Troubleshooting

故障排查

IssueSolution
"no server running"Start with
tmux
or
tmux new
"sessions should be nested"Unset
$TMUX
or use
tmux -u
Detached session lostCheck
tmux ls
, attach with
tmux attach
Colors not workingSet
TERM=xterm-256color
or
set -g default-terminal "tmux-256color"
Mouse not working
set -g mouse on
in config
问题解决方案
"no server running"执行
tmux
tmux new
启动服务器
"sessions should be nested"取消
$TMUX
变量或使用
tmux -u
断开的会话丢失执行
tmux ls
查看,使用
tmux attach
重新连接
颜色显示异常设置
TERM=xterm-256color
或在配置中添加
set -g default-terminal "tmux-256color"
鼠标功能无效在配置文件中添加
set -g mouse on