安装

yum install -y screen
[root@instance-- ~]# screen --help
Use: screen [-opts] [cmd [args]]
or: screen -r [host.tty] Options:
- Resolve hostnames only to IPv4 addresses.
- Resolve hostnames only to IPv6 addresses.
-a Force all capabilities into each window's termcap.
-A -[r|R] Adapt all windows to the new display width & height.
-c file Read configuration file instead of '.screenrc'.
-d (-r) Detach the elsewhere running screen (and reattach here).
-dmS name Start as daemon: Screen session in detached mode.
-D (-r) Detach and logout remote (and reattach here).
-D -RR Do whatever is needed to get a screen session.
-e xy Change command characters.
-f Flow control on, -fn = off, -fa = auto.
-h lines Set the size of the scrollback history buffer.
-i Interrupt output sooner when flow control is on.
-l Login mode on (update /var/run/utmp), -ln = off.
-ls [match] or
-list Do nothing, just list our SockDir [on possible matches].
-L Turn on output logging.
-m ignore $STY variable, do create a new screen session.
-O Choose optimal output rather than exact vt100 emulation.
-p window Preselect the named window if it exists.
-q Quiet startup. Exits with non-zero return code if unsuccessful.
-Q Commands will send the response to the stdout of the querying process.
-r [session] Reattach to a detached screen process.
-R Reattach if possible, otherwise start a new session.
-s shell Shell to execute rather than $SHELL.
-S sockname Name this session <pid>.sockname instead of <pid>.<tty>.<host>.
-t title Set title. (window's name).
-T term Use term as $TERM for windows, rather than "screen".
-U Tell screen to use UTF- encoding.
-v Print "Screen version 4.01.00devel (GNU) 2-May-06".
-wipe [match] Do nothing, just clean up SockDir [on possible matches].
-x Attach to a not detached screen. (Multi display mode).
-X Execute <cmd> as a screen command in the specified session.

创建一个后台任务

[root@instance-- ~]# screen -R `date +%Y%m%d%H`

查看后台任务

[root@instance-- ~]# screen -ls
There is a screen on:
.20200326 (Detached)
Socket in /var/run/screen/S-root.

恢复一个后台任务

[root@instance-- ~]# screen -r 20200326

报错:

Cannot open your terminal '/dev/pts/1' - please check.

执行: script /dev/null

参数说明

-A  将所有的视窗都调整为目前终端机的大小。
-d <作业名称>  将指定的screen作业离线。
-h <行数>  指定视窗的缓冲区行数。
-m  即使目前已在作业中的screen作业,仍强制建立新的screen作业。
-r <作业名称>  恢复离线的screen作业。
-R  先试图恢复离线的作业。若找不到离线的作业,即建立新的screen作业。
-s  指定建立新视窗时,所要执行的shell。
-S <作业名称>  指定screen作业的名称。
-v  显示版本信息。
-x  恢复之前离线的screen作业。
-ls或--list  显示目前所有的screen作业。
-wipe  检查目前所有的screen作业,并删除已经无法使用的screen作业。

常用screen参数

screen -S yourname -> 新建一个叫yourname的session
screen -ls -> 列出当前所有的session
screen -r yourname -> 回到yourname这个session
screen -d yourname -> 远程detach某个session
screen -d -r yourname -> 结束当前session并回到yourname这个session

在每个screen session 下,所有命令都以 ctrl+a(C-a) 开始。

C-a ? -> 显示所有键绑定信息
C-a c -> 创建一个新的运行shell的窗口并切换到该窗口
C-a n -> Next,切换到下一个 window
C-a p -> Previous,切换到前一个 window
C-a .. -> 切换到第 .. 个 window
Ctrl+a [Space] -> 由视窗0循序切换到视窗9
C-a C-a -> 在两个最近使用的 window 间切换
C-a x -> 锁住当前的 window,需用用户密码解锁
C-a d -> detach,暂时离开当前session,将目前的 screen session (可能含有多个 windows) 丢到后台执行,并会回到还没进 screen 时的状态,此时在 screen session 里,每个 window 内运行的 process (无论是前台/后台)都在继续执行,即使 logout 也不影响。
C-a z -> 把当前session放到后台执行,用 shell 的 fg 命令则可回去。
C-a w -> 显示所有窗口列表
C-a t -> Time,显示当前时间,和系统的 load
C-a k -> kill window,强行关闭当前的 window
C-a [ -> 进入 copy mode,在 copy mode 下可以回滚、搜索、复制就像用使用 vi 一样
C-b Backward,PageUp
C-f Forward,PageDown
H(大写) High,将光标移至左上角
L Low,将光标移至左下角
移到行首
$ 行末
w forward one word,以字为单位往前移
b backward one word,以字为单位往后移
Space 第一次按为标记区起点,第二次按为终点
Esc 结束 copy mode
C-a ] -> Paste,把刚刚在 copy mode 选定的内容贴上

最新文章

  1. Ctrip Mydream
  2. 恢复SharePoint Server 2013 中的“新颖快建视图”
  3. zepto.js使用前注意
  4. 详细的图文教程来实现 eclipse环境下如何配置tomcat,并且把项目部署到Tomcat服务器上
  5. jQuery基础学习5——JavaScript方法获取页面中的元素
  6. Intel大坑之中的一个:丢失的SSE2 128bit/64bit 位移指令,马航MH370??
  7. CSS基础-引入方法,选择器,继承
  8. Android Animation学习(二) ApiDemos解析:基本Animatiors使用
  9. 介绍一款轻量级js控件:easy.js
  10. MVC 使用IBatis.net
  11. SpringMVC的数据格式化-注解驱动的属性格式化
  12. ⑧bootstrap组件 文字图片 下拉菜单 按钮组 使用基础案例
  13. python全栈学习--day11(函数高级应用)
  14. Effective C++ 读书笔记(1-7)
  15. [原创]如果软件在网络磁盘中或移动磁盘中运行时需要解决 exception C0000006 异常问题
  16. 洛谷 P1605 迷宫
  17. 超经典sql练习题,在teradata上实现
  18. Spark中hashshuffle与sortshuffle
  19. 20145325张梓靖 实验二&quot;Java面向对象程序设计&quot;
  20. BZOJ5072 小A的树(树形dp)

热门文章

  1. apache2_fastcgi_python
  2. DRF cbv源码分析 restful规范10条 drf:APIView的源码 Request的源码 postman的安装和使用
  3. Jmeter之逻辑控制器/定时器
  4. 牛客 110D 矩阵
  5. APOC官网触发器示例执行后Web页面一直转圈
  6. react中数据持久化缓存redux-persist
  7. 管家婆crm9.2 sp2升级问题求助及解决方案
  8. winfrom 点击按钮button弹框显示颜色集
  9. SQL SERVER中Datetime时间的范围与.net的DateTime对象的区别
  10. curl 的使用