tmux

tmux

原文日期: 2017-06-19
来源: https://github.com/wlz0726/wlz0726.github.io


tmux 终端复用器

安装

先安装 libevent 2.x(tmux 依赖):

1
2
3
4
5
# macOS
brew install libevent

# Ubuntu/Debian
sudo apt-get install libevent-dev

安装 tmux

1
2
3
4
5
6
7
8
9
10
11
# macOS
brew install tmux

# Ubuntu/Debian
sudo apt-get install tmux

# 源码编译
wget https://github.com/tmux/tmux/releases/download/2.5/tmux-2.5.tar.gz
tar -xzf tmux-2.5.tar.gz
cd tmux-2.5
./configure && make && sudo make install

基本命令

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# 新建会话
tmux new -s session_name

# 列出会话
tmux ls

# 附加会话
tmux attach -t session_name

# 分离会话
Ctrl+b d

# 杀死会话
tmux kill-session -t session_name

窗口管理

窗格管理

配置文件 ~/.tmux.conf

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# 历史记录限制
set -g history-limit 10000

# 启用鼠标
set -g mouse on

# 状态栏设置
set -g status-bg black
set -g status-fg white
set -g status-left '[#S] '
set -g status-right ' %Y-%m-%d %H:%M '

# 窗口状态
setw -g window-status-current-format '#I:#W'

常用场景

1. 远程工作

在远程服务器上启动 tmux 会话,即使断开连接,任务也会继续运行。

2. 多任务处理

一个窗口写代码,一个窗口运行测试,一个窗口查看日志。

3. 配对编程

使用 tmux 共享会话,多人同时编辑。


此文档为 GitHub 博客自动归档