linux-screen终端会话后台运行
screen
linux终端关闭,也不影响终端里命令的正常运行,就需要screen及tmux
特点
- 会话恢复
- 多窗口
- 会话共享
install && used
yum install -y screen
//状态说明
Attached 在线,在终端中
Detached 离线,关闭终端
dead 会话死掉
//创建会话,且指定名字
screen -S gaga
//查看会话
[root@c7-101 ~]# screen -ls
There are screens on:
1515.gaga (Attached 在线) -> Detached(离线)
993.pts-1.c7-101 (Attached)
2 Sockets in /var/run/screen/S-root.
//恢复登录到会话(pid/name都可以登录)
screen -r 1515
screen -r gaga
//会话离线
screen -d gaga
screen -d -r yy //离线当前会话,登录到yy会话
//会话共享(多个用户可以看到使用一个会话的terminal)
screen -S all //打开终端a
screen -x //另外打开终端b,同步会话
screen -x -r all //如果存在多个会话指定那个实时同步
//清理dead会话
screen -wipe
//退出会话
screen -r xxx
exit
screen -ls
screen help
screen
-S 指定会话名称
-d 会话离线
-r 恢复会话
-x 恢复所有离线会话
-ls/-list 查看所有会话
-wipe 检查自动讲无法使用会话删除
[root@c7-101 ~]# screen -h
Use: screen [-opts] [cmd [args]]
or: screen -r [host.tty]
Options:
-4 Resolve hostnames only to IPv4 addresses.
-6 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. //连接到session
-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-8 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.