tmux 是终端复用器,在一个窗口运行多个会话,断开连接后会话保持运行。
安装
1
2
3
4
5
| # Debian/Ubuntu
sudo apt install tmux
# RHEL/Fedora
sudo dnf install tmux
|
启动会话
1
2
| tmux # 新会话
tmux new -s my_session # 命名会话
|
会话管理
| 操作 | 命令/快捷键 |
|---|
| 分离会话 | Ctrl-b d |
| 列出会话 | tmux ls |
| 重连会话 | tmux attach -t my_session |
| 删除会话 | tmux kill-session -t my_session |
| 删除所有 | tmux kill-server |
窗口操作
| 操作 | 快捷键 |
|---|
| 新建窗口 | Ctrl-b c |
| 下一个窗口 | Ctrl-b n |
| 上一个窗口 | Ctrl-b p |
| 列出窗口 | Ctrl-b w |
| 重命名窗口 | Ctrl-b , |
窗格操作
| 操作 | 快捷键 |
|---|
| 垂直分割 | Ctrl-b % |
| 水平分割 | Ctrl-b " |
| 切换窗格 | Ctrl-b 方向键 |
| 关闭窗格 | exit 或 Ctrl-d |
配置示例
1
2
3
4
| # ~/.tmux.conf
set -g prefix C-a # 前缀键改为 Ctrl-a
set -g mouse on # 启用鼠标
bind r source-file ~/.tmux.conf \; display "Reloaded!"
|
会话持久化
使用 tmux-resurrect 插件保存和恢复会话:
1
2
3
4
5
6
7
8
9
10
11
| # 安装 TPM
git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm
# ~/.tmux.conf 添加
set -g @plugin 'tmux-plugins/tmux-resurrect'
run '~/.tmux/plugins/tpm/tpm'
# 使用
# prefix + I 安装插件
# prefix + Ctrl-s 保存会话
# prefix + Ctrl-r 恢复会话
|
Comments