tmux 操作文档

2020年3月29日 作者 C0isini

一、安装 tmux

1、centos

yum install -y tmux 

二、使用

1、新建会话

1.1、会新建会话,但是会话名会是 0 1 2 这种递增的

tmux

[root@110 ~]# tmux ls
0: 1 windows (created Sun Mar 29 17:17:33 2020) [139x37]
1: 1 windows (created Sun Mar 29 17:19:02 2020) [139x37]
2: 1 windows (created Sun Mar 29 17:19:57 2020) [139x37]

1.2、新建会话并自定义会话名

tmux new -s session_name

[root@110 ~]# tmux new -s test
[3]+  Stopped                 tmux new -s test
# tmux ls
0: 1 windows (created Sun Mar 29 17:17:33 2020) [139x37]
1: 1 windows (created Sun Mar 29 17:19:02 2020) [139x37]
2: 1 windows (created Sun Mar 29 17:19:57 2020) [139x37]
3: 1 windows (created Sun Mar 29 17:21:33 2020) [101x25]
test: 1 windows (created Sun Mar 29 17:25:20 2020) [101x25] (attached)

2、显示所有的会话

tmux ls

[root@110 ~]# tmux ls
0: 1 windows (created Sun Mar 29 17:17:33 2020) [139x37]
1: 1 windows (created Sun Mar 29 17:19:02 2020) [139x37]
2: 1 windows (created Sun Mar 29 17:19:57 2020) [139x37]
3: 1 windows (created Sun Mar 29 17:21:33 2020) [101x25]

3、连接会话

3.1、连接上一个会话

tmux a

3.2、指定要连接的会话

tmux a -t session_name

例如:

tmux a -t 1

4、保存会话并退出

会话内顺序执行

Ctrl + b

Ctrl + z

[root@110 ~]# tmux a -t 1
[5]+  Stopped                 tmux a -t 1

5、会话内切换其他会话

会话内执行

Ctrl + b

s

显示下面的列表,移动光标到指定的会话回车即可切换

(0) + 0: 1 windows
(1) + 1: 1 windows
(2) + 2: 1 windows
(3) + 3: 1 windows
(4) + test: 1 windows (attached)

6、删除指定会话

tmux kill-session -t session_name

例如:

tmux kill-session -t 0

[root@110 ~]# tmux ls
 0: 1 windows (created Sun Mar 29 17:17:33 2020) [139x37]
 1: 1 windows (created Sun Mar 29 17:19:02 2020) 101x25
 2: 1 windows (created Sun Mar 29 17:19:57 2020) [139x37]
 3: 1 windows (created Sun Mar 29 17:21:33 2020) [101x25]
 test: 1 windows (created Sun Mar 29 17:25:20 2020) [101x25]
 [root@110 ~]# tmux kill-session -t 0
 [root@110 ~]# tmux ls
 1: 1 windows (created Sun Mar 29 17:19:02 2020) [101x25]
 2: 1 windows (created Sun Mar 29 17:19:57 2020) [139x37]
 3: 1 windows (created Sun Mar 29 17:21:33 2020) [101x25]
 test: 1 windows (created Sun Mar 29 17:25:20 2020) [101x25]

7、删除指定会话之外的会话

tmux kill-session -a -t session_name

[root@110 ~]# tmux ls
 1: 1 windows (created Sun Mar 29 17:19:02 2020) [101x25]
 3: 1 windows (created Sun Mar 29 17:21:33 2020) [101x25]
 test: 1 windows (created Sun Mar 29 17:25:20 2020) [101x25]
 [root@110 ~]#
 [root@110 ~]#
 [root@110 ~]# tmux kill-session -a -t test
 [root@110 ~]#
 [root@110 ~]#
 [root@110 ~]# tmux ls
 test: 1 windows (created Sun Mar 29 17:25:20 2020) [101x25]
 [root@110 ~]#

8、销毁所有的会话

tmux kill-server

[root@110 ~]# tmux kill-server
[root@110 ~]#
[root@110 ~]# tmux ls
failed to connect to server

9、重命名会话

tmux rename-session -t session_name new_session_name

 [root@110 ~]# tmux ls
 0: 2 windows (created Sun Mar 29 17:46:35 2020) [101x25]
 1: 1 windows (created Sun Mar 29 17:53:11 2020) [101x25]
 2: 1 windows (created Sun Mar 29 17:53:20 2020) 101x25
 [root@110 ~]# tmux rename-session -t 0 test
 [root@110 ~]# tmux ls
 1: 1 windows (created Sun Mar 29 17:53:11 2020) [101x25]
 2: 1 windows (created Sun Mar 29 17:53:20 2020) [101x25]
 test: 2 windows (created Sun Mar 29 17:46:35 2020) [101x25]