通俗简介:

screen 简单应用:

screen myprogram  // 通过screen启动一个程序, 或者screen -L myprogram 加上 -L 是为了 turns on logging to ~/screenlog.0
ctr+a 然后再按一下 d   // 使程序在后台运行,即detach
screen -ls           // 列出在screen后台运行的程序,以及ID(例如4491.pts-2.localhost)
screen -r ID         // 恢复运行程序到terminal,例如:screen -r 4491
ctr+a :sessionname mySessionName  // Ctrl + a 再输入:sessionname,空格, 然后输入期望名字
exit //退出当前screen会话(同 ctrl+a 再按 k),有时候会打开很多screen,可以通过exit退出。

在screen中滚屏:

Ctrl+a+[ to enter Copy Mode, then scroll up/down using keys j or k.

多窗口管理:

如果在某一个终端中运行了多次screen,即有嵌套的多层screen,则 ctrl+a 再按 w 可查看当前终端下的所有screen窗口,* 号 表示的是当前会话所在的窗口,然后 ctrl+a 再按 0~9 即可切换到某个对应窗口。

介绍screen的很好的文章,just read it:
http://www.ibm.com/developerworks/cn/linux/l-cn-screen/

复杂点的应用如下:


One way:

When you use screen you need to detach with CTRL+A+D before you exit ssh.

Alternatively, if you want to run a process directly with screen you can use

screen -dmSL [session name] [commands]
-d: starts a screen session and immediately detaches from it
-m: forces creating a new screen session
-S: lets you give the session a name
-L: turns on logging to ~/screenlog.0

example:

screen -dmSL myalias myscript.sh

You can then either:

resume later using screen -x myalias

or

check the log file less -r ~/screenlog.0



Another way:

Screen Command Example 1: Execute a command (or shell-script), and detach the screen

$ screen unix-command-to-be-executed
$ screen ./unix-shell-script-to-be-executed

Once you’ve used the screen command, you can detach it from the terminal using any one of the following method.

Screen Detach Method 1: Detach the screen using CTRL+A d

When the command is executing, press CTRL+A followed by d to detach the screen.

Screen Detach Method 2: Detach the screen using -d option

When the command is running in another terminal, type the command as following.

$ screen -d SCREENID

Screen Command Example 2: List all the running screen processes

You can list all the running screen processes using screen -ls command.

For example:

On terminal 1 you did the following:

$ screen ./myscript.sh

From terminal 2 you can view the list of all screen processes. You can also detach it from terminal 2 as shown below.

$ screen -ls
There is a screen on:4491.pts-2.localhost   (Attached)
1 Socket in /var/run/screen/S-i5.
$ screen -d 4491.pts-2.localhost
[4491.pts-2.localhost   detached.]

Screen Command Example 3: Attach the Screen when required

You can attach the screen at anytime by specifying the screen id as shown below. You can get the screen id from the “screen -ls” command output.

$ screen -r 4491.pts-2.FC547





tmux:

我们先来理解下tmux的几个元素。tmux的主要元素分为三层:

  • Session 一组窗口的集合,通常用来概括同一个任务。Session可以有自己的名字便于任务之间的切换。detach和attach都是基于Session的,通过 tmux 命令创建一个Session。
  • Window 单个可见窗口,Windows有自己的编号。在tmux的session中通过 C-b+c 来创建。
  • Pane 窗格,被划分成小块的窗口。通过在Window中 C-b+" (水平分割,左右两个Pane) 或者 C-b+% (垂直分割,上下两个Pane)。

即:
session: 会话,一个服务器可以包含多个session
window: 窗口,一个session可以包含多个window
pane: 面板,一个window可以包含多个pane

快捷键一览:

tmux     #开启tmux,新建一个session: t
C-b "   #水平分割窗口(上下两个小窗口)
C-b %   #垂直分割窗口(左右两个小窗口)
C-b (方向键) # 在小窗口中切换
C-b(不放)+左右方向键  # 调整小窗口的大小,或者上下方向键调整上下窗口大小
C-b x #关闭当前光标处的小窗口或者如果只有一个窗口则关闭window
tmux ls #显示已有tmux列表(C-b s)
tmux attach-session -t n #重新连接上第n个session, 即attach。或者: tmux a –t nC-b c #创建一个新的窗口
C-b n #切换到下一个窗口
C-b p #切换到上一个窗口
C-b l #最后一个窗口,和上一个窗口的概念不一样哟,谁试谁知道
c-b w #通过上下键选择当前窗口中打开的会话
C-b n #直接跳到第n个窗口
C-b & #退出当前窗口(kill window,同时关闭所有小窗口)

C-b d 临时断开会话,即dettach,类似screen的 ctrl+a+d (通过tmux ls查看Session号,例如0,然后tmux attach-session -t 0 重新attach)

C-b o 在小窗口中切换
C-b [ 启动滚动条,可以通过上下箭头键或者鼠标滚轮来查看内容;或者对所有窗口开启的话: C-b后,输入setw -g mode-mouse on。
C-b ! 新建一个窗口,并将当前小窗口最大化

哈,家里的小工厂,占个位: http://www.herofireworks.com/

screen tmux 技巧:linux后台运行程序相关推荐

  1. Linux 后台运行程序 Screen 服务器

    Linux后台运行python程序,断网||关机后仍能在继续在服务器上运行 常用screen参数: screen -S sess_name -> 新建一个叫sess_name的session s ...

  2. linux后台运行程序命令screen

    linux后台运行程序命令screen 前言 screen的简单使用 1.创建一个会话窗口 2. 查看我们screen的会话 3. 恢复会话窗口,就是继续查看我们后台运行的程序 前言 我们在服务器终端 ...

  3. linux 后台运行程序

    前言 一般为了程序后台运行,我们需要使用nohup命令. 此时需要对程序运行时所产生的输出信息记录,因此就需要使用linux的信息输出命令 START 一个例子 比如要让redis-server程序后 ...

  4. Linux 后台运行程序方法总结

      在用服务器跑数据的时候经常会遇到数据量大,速度慢的情况,动不动需要用好几天甚至上十天,但电脑总不能好几天不关终端,且保证不断网吧.所以这时候我们就需要将程序放到后台运行,不依赖于终端.关于原理,我 ...

  5. linux 后台运行程序命令

    文章目录 一.cmd & 二.nohup command & 这篇文章记录了两种linux程序后台运行的方式,两种方式略有区别,各位根据需求使用. 一.cmd & 通过 cmd ...

  6. linux程序已经在后台运行冻结了_如何使程序在Linux后台运行

    经常在Linux上面运行程序都有这样的体验: 某个程序运行的时候,会产生大量的log(提示)信息,但实际上我们只想让它跑一下而已,log暂时不需要或者后面才有需要. 同时run多个相同或者不同程序的时 ...

  7. Linux nohup实现后台运行程序及查看(nohup与)

    Linux nohup实现后台运行程序及查看(nohup与&) 更新时间:2019年09月11日 09:28:40 作者:猿的生活 这篇文章主要介绍了Linux nohup实现后台运行程序及查 ...

  8. linux中启动 java -jar 后台运行程序

    ps -ef | grep java  查询java 端口占用 linux中启动 java -jar 后台运行程序 直接用java -jar xxx.jar,当退出或关闭shell时,程序就会停止掉. ...

  9. 在linux前台和后台运行程序

    为什么要在linux命令前加上 ./ 简述 在chinaunix 论坛里找到的答案 原来Quote: unix或linux中除了path系统变量外的目录下的命令都要加./ 修改用户的 .bash_pr ...

最新文章

  1. ML之LoRSGD:基于LoR(逻辑回归)、SGD梯度下降算法对乳腺癌肿瘤(10+1)进行二分类预测(良/恶性)
  2. 【运营】运营必看!如何吸引用户主动的参与活动?
  3. 【Linux】GCC程序开发工具(上)
  4. MPEG中面向沉浸式视觉体验的标准化活动
  5. linux显示点阵字体,Fedora 17中文字体显示点阵状的解决方法
  6. table内容保存到Excel中
  7. Android Studio 将github作为远程maven仓库
  8. JS基础知识 --变量类型和计算
  9. 拖延2年的Bug,Linux 上的三星 SSD 驱动错误终于得到修复
  10. 可转债数据一览表集思录_可转债交易常用的一些工具与手法 支独秀 股票大作手回忆录 自己常看的可转债数据网站: 集思录:网页链接 富投网:网页链接 可转债新债申购还不是闭着眼睛申... - 雪球...
  11. 相机变换AND正交投影AND透视投影
  12. CS5261|CS5265|Type-C转HDMI 4K30HZ 4K60HZ音视频
  13. 软件测试技能大赛山东省,2018年全国职业院校技能大赛山东省选拔赛高职组软件测试赛项规程.pdf...
  14. 游戏本地文件乱码问题
  15. excel 妙用选择性粘贴
  16. mac 卸载java7_mac卸载jdk
  17. C语言直接驱动硬件实现PC机的串口操作
  18. 心灵驿站——洗尽铅华
  19. 京东软件测试岗:不忍直视的三面,幸好做足了准备,月薪18k,已拿offer
  20. 直接将ppt转换成word格式的方法

热门文章

  1. python数据分析实例1-基金定投
  2. 斯坦福Nature论文宣布新突破:深度学习皮肤癌诊断达专家水平
  3. 扫雷游戏分析实现(完整代码)
  4. 【数据结构】单链表的操作
  5. Photoshop给草坡上的人物加上大气的霞光
  6. Java 位运算符的基本用法【1】
  7. 如何生成带统计参数的二维码渠道监测
  8. 动态设置路由,扫码进入页面,从二维码里拿到参数
  9. 圆桌论坛|专家齐聚一堂,区块链溯源技术如何实现农产品安全可信
  10. lda 协方差矩阵_协方差矩阵概念及计算