TMux 安装

安装依赖 ncurses

1
do ~/tmux # yum -y install ncurses-devel

安装依赖 libevent

官网 http://libevent.org/ 下载包 2.1.8-stable

1
2
3
do ~/tmux/libevent-2.1.8-stable # ./configure --prefix=/usr/local/libevent
do ~/tmux/libevent-2.1.8-stable # make -j8
do ~/tmux/libevent-2.1.8-stable # make install

安装 tmux

官网 https://github.com/tmux/tmux 下载源码包 tmux-2.6

1
2
do ~/tmux/tmux-2.6 # CFLAGS="-I/usr/local/libevent/include" LDFLAGS="-L/usr/local/libevent/lib" ./configure --prefix=/usr/local/tmux
do ~/tmux/tmux-2.6 # make -j8 && make install

运行,找不到依赖:

1
2
3
4
5
6
7
8
9
10
do ~/tmux/tmux-2.6 # ldd /usr/local/tmux/bin/tmux
linux-vdso.so.1 => (0x00007fff61de6000)
libutil.so.1 => /lib64/libutil.so.1 (0x00007f21d7b9f000)
libtinfo.so.5 => /lib64/libtinfo.so.5 (0x00000032abe00000)
libevent-2.1.so.6 => not found
librt.so.1 => /lib64/librt.so.1 (0x00007f21d7996000)
libresolv.so.2 => /lib64/libresolv.so.2 (0x00007f21d777c000)
libc.so.6 => /lib64/libc.so.6 (0x00007f21d73e7000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f21d71ca000)
/lib64/ld-linux-x86-64.so.2 (0x00007f21d7db4000)

把libevent放到ldconfig搜索路径下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
do ~/tmux/tmux-2.6 # echo /usr/local/libevent/lib > /etc/ld.so.conf.d/libevent.conf
do ~/tmux/tmux-2.6 # ldconfig
do ~/tmux/tmux-2.6 # ldd /usr/local/tmux/bin/tmux
linux-vdso.so.1 => (0x00007ffe1a7d0000)
libutil.so.1 => /lib64/libutil.so.1 (0x00007f53dc0a0000)
libtinfo.so.5 => /lib64/libtinfo.so.5 (0x00000032abe00000)
libevent-2.1.so.6 => /usr/local/libevent/lib/libevent-2.1.so.6 (0x00007f53dbe4d000)
librt.so.1 => /lib64/librt.so.1 (0x00007f53dbc45000)
libresolv.so.2 => /lib64/libresolv.so.2 (0x00007f53dba2b000)
libc.so.6 => /lib64/libc.so.6 (0x00007f53db696000)
libcrypto.so.10 => /usr/lib64/libcrypto.so.10 (0x00000032b2200000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f53db479000)
/lib64/ld-linux-x86-64.so.2 (0x00007f53dc2b5000)
libdl.so.2 => /lib64/libdl.so.2 (0x00007f53db274000)
libz.so.1 => /lib64/libz.so.1 (0x00000032a3600000)
do ~/tmux/tmux-2.6 # ln -s /usr/local/tmux/bin/tmux /usr/bin/tmux

安装到其他机器,这次用scp拷贝到其他机器,不用tar打包:

1
2
do ~/tmux/tmux-2.6 # scp /usr/local/libevent/lib/libevent-2.1.so.6 root@200.200.88.104:/lib64
do ~/tmux/tmux-2.6 # scp /usr/local/tmux/bin/tmux root@200.200.88.104:/usr/bin/

快捷键

默认是Ctrl + b,即C-b:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
C-b ? 显示快捷键帮助
C-b C-o 调换窗口位置
C-b " 模向分隔窗口
C-b % 纵向分隔窗口
C-b q 显示分隔窗口的编号
C-b o 跳到下一个分隔窗口
C-b 上下左右键 切换上下左右分隔窗口
C-b C-方向键 调整分隔窗口大小
C-b c 创建新窗口
C-b 0~9 选择几号窗口
C-b c 创建新窗口
C-b n 选择下一个窗口
C-b l 最后使用的窗口
C-b p 选择前一个窗口
C-b w 以菜单方式显示及选择窗口
C-b s 以菜单方式显示和选择会话
C-b t 显示时钟

简单用法

具体文档参考 https://leanpub.com/the-tao-of-tmux/read

创建一个新session:

1
host ~/w # tmux

创建一个命名为w0的session,new-session可简写为new也行,他的原则是,只要前缀能唯一确定一个命令即可,例如attach简写为att或at都可以:

1
host ~/w # tmux new-session -s w0

列出当前有哪些session:

1
2
host ~/w # tmux ls
0: 1 windows (created Tue Nov 14 19:23:37 2017) [270x56] (attached)

attach 0号/w0 session:

1
2
host ~/w # tmux at -t 0
host ~/w # tmux at -t w0

效果

tmux-screen