美文网首页
tmux--后台运行利器

tmux--后台运行利器

作者: 小淼不卖萌 | 来源:发表于2018-09-18 00:56 被阅读0次

1. 需求情景(目前的遇到的)

  • 需要在远程服务器上跑程序,关闭终端或者断网后程序就终止运行
  • 某些情况想要保存工作环境的状态

2. 安装

# ubuntu
apt install tmux

# centos
yum install tmux

3. 进入tmux

  • 进入到临时创建的session中
    tmux
    
  • 创建指定命名的session
    tmux new -s  your_session_name
    
  • 查看当前所有的tmux-session
    tmux ls
    

4. 退出tmux的session(window)

  • ctrl + d
  • exit

5. 命令(session运行环境)在后台执行

    1. 进入到tmux后,ctrl + b 进入到快捷键
    1. 按d(会回到终端的shell中)

6. 选择想进入的session

    1. 进入到tmux后,ctrl + b 进入快捷键
    1. 按s显示下图
    1. 按回车,或者按数字键/或/前面的名称 (此处待熟悉)
    tmux选择session(window).png

7. 在session中可以创建多个window

    1. 进入到tmux后,ctrl + b 进入到快捷键
    1. 按c(会进入到新创建的window中)
  • 3.1 按前面【6. 选择想进入的session】操作会显示列出window状态
ctrl +b 后按s.png
  • 3.2 /或/按【3. 进入tmux-- 查看当前所有的tmux-session】操作,列出window状态
    [root@localhost ~]# tmux  ls
    0: 1 windows (created Mon Sep 17 12:23:08 2018) [110x47]
    2: 1 windows (created Mon Sep 17 12:35:36 2018) [110x25]
    sss: 2 windows (created Mon Sep 17 12:34:34 2018) [110x47] (attached)
    

8. 回到session(window)

  • 命令行状态执行 tmux -a 回到最近退出的session
    tmux -a
    
  • 进入到目标session
# 查看session
[root@localhost ~]# tmux ls
0: 1 windows (created Mon Sep 17 12:23:08 2018) [110x25]
2: 1 windows (created Mon Sep 17 12:35:36 2018) [110x25]
sss: 2 windows (created Mon Sep 17 12:34:34 2018) [110x47] (attached)

# 进入到目标session
[root@localhost ~]# tmux a -t sss
[detached]
[root@localhost ~]# tmux attach -t sss
[detached]

9. tmux其他功能 & 配置

相关文章

网友评论

      本文标题:tmux--后台运行利器

      本文链接:https://www.haomeiwen.com/subject/rpejnftx.html