tmux tutorial on ubuntu 16.04


Guide

install

sudo apt-get -y install tmux

usage

1) 默认创建一个会话,以数字命名。(不推荐)
[root@Centos6 ~]# tmux

2)新建会话,比如新创建一个会话以"ccc"命名
[root@Centos6 ~]# tmux new -s ccc

1) 加上参数-d,表示在后台新建会话
root@bobo:~# tmux new -s shibo -d
root@bobo:~# tmux ls
shibo: 1 windows (created Tue Oct  2 19:22:32 2018) [135x35]

4)查看创建得所有会话
[root@Centos6 ~]# tmux ls
0: 1 windows (created Wed Aug 30 17:58:20 2017) [112x22](attached)    #attached表示该会话是当前会话
aaa: 2 windows (created Wed Aug 30 16:54:33 2017) [112x22]
ccc: 1 windows (created Wed Aug 30 17:01:05 2017) [112x22]

5)从终端环境进入会话
[root@Centos6 ~]# tmux attach -t aaa 

6)快捷键退出会话:
登到某一个会话后,依次按键ctrl-b + d,这样就会退化该会话,但不会关闭会话;
按键ctrl + d,就会在退出会话的通话也关闭了该会话。

7)关闭会话(销毁会话)
[root@Centos6 ~]# tmux ls
aaa: 2 windows (created Wed Aug 30 16:54:33 2017) [112x22]
bbb: 1 windows (created Wed Aug 30 19:02:09 2017) [112x22]

[root@Centos6 ~]# tmux kill-session -t bbb

[root@Centos6 ~]# tmux ls
aaa: 2 windows (created Wed Aug 30 16:54:33 2017) [112x22]

8)重命名会话
[root@Centos6 ~]# tmux ls  
wangshibo: 1 windows (created Sun Sep 30 10:17:00 2018) [136x29] (attached)

[root@Centos6 ~]# tmux rename -t wangshibo kevin

[root@Centos6 ~]# tmux ls
kevin: 1 windows (created Sun Sep 30 10:17:00 2018) [136x29] (attached)

9)发送命令到回话并执行
[root@Centos6 ~]# tmux send -t session_name "command" ENTER

nohup

nohup <command> [argument…] &

使用tmux打开一个终端窗口,可以在窗口里执行一个长时间运行的交互式命令操作,令其一直在后台跑着,并且在按键ctrl-b-d后,可以无感知的退出窗口,
而退出后窗口不会关闭,即窗口里执行的交互命令也不会结束。这比起传统的”nohup command & (然后按ctrl+c)”的方式要好用很多。

tmux new -s aaa

sudo apt-get -y update 
ctrl+b + d

similar tools

  • screen

Reference

History

  • 20181214: created.

Author: kezunlin
Reprint policy: All articles in this blog are used except for special statements CC BY 4.0 reprint polocy. If reproduced, please indicate source kezunlin !
评论
  TOC