1. 安装screen
- ubuntu
sudo apt-get install screen
- CentOS
yum install screen
2. screen常用命令
2.1 创建session
执行下方命令会创建一个名为yourSessionName的session,并进入了这个session
screen -S yourSessionName
2.2 退出session(session状态是detached,但session中的程序仍在运行)
- 在当前服务器别的shell窗口输入:
screen -d yourSessionName # yourSessionName被detached ,但是session所在的shell窗口还在
screen -D yourSessionName # yourSessionName被detached ,并且session所在的shell窗口也logout
- 或是直接把attach了当前session的shell窗口关闭
2.3 返回session
screen -r yourSessionName
如果yourSessionName 已经在其他窗口
screen -dr yourSessionName #将yourSessionName从其他地方detach再reattach到当前位置
2.4 查看当前所有session
screen -ls
session的代号.名字, session的创建时间, session的链接状态
session的代号和名字是等价的,使用任意一个或者两个合一起的全称都可以对该seesion做操作
screen -r 50930
screen -r pcgc
screen -r 50930.pcgc
2.5 删除session(session直接被删除,session中的程序也不再运行)
#先进入要退出的session
screen -r yourSessionName
#进入之后,再输入:
exit
# 然后shell上会输出[screen is terminating],并且这个session已经被删除了
3. screen 完整命令
(base) fanxing@amax:~$ 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 windows 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-8 encoding.
-v Print "Screen version 4.03.01 (GNU) 28-Jun-15".
-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.