创建与重新连接 tmux 会话
在终端复用器中运行工作,SSH 断线、笔记本休眠、窗口关闭都不会终止正在运行的任务。
执行 tmux new -s work 创建命名会话,按 Ctrl-b d 脱离,之后在任意终端执行 tmux attach -t work 重新接入。
01命令
命令
$ tmux new -s work # create session 'work'
tmux attach -t work # reattach later (even from another SSH login)
# inside tmux: Ctrl-b d detach, Ctrl-b % split pane, Ctrl-b d then exit02作用说明
tmux 的会话由服务端进程维持,客户端断开后任务照常运行——通宵构建或 vim 会话可以熬过掉线的 VPN。所有命令经由前缀键 Ctrl-b 加字母触发:d 脱离,% 和 " 分别左右、上下分屏,tmux ls 可查看会话列表。tmux attach -t work 会从任何能访问该主机的机器恢复到离开时的现场。
03风险
!注意: 同名 tmux 会话不能共存——若提示 duplicate session,说明应改为 attach,或用 tmux kill-session -t work 清理失效会话。
04撤销
撤销
$ tmux kill-session -t work05来源
- tmux(1) — Linux man page依据: tmux man page: 'tmux is a terminal multiplexer' documenting new-session, attach-session, and detach-client.
- Arch Wiki: tmux依据: Practical guide to sessions, prefix key bindings (Ctrl-b), pane splitting, and reattaching after SSH disconnects.
最后验证: 2026-09-17 · 分类: 开发者