适用环境LInux
1、安装
ubuntu:
sudo apt install screen
centos:
yum install screen
2、所有命令
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.
-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.
3、创建新的窗口
screen
直接使用screen创建,但是这样没哟名字来标识不同的窗口,不容易区分。可以使用以下方法:
screen -S new_screen
创建了一个名字叫new_screen的窗口。
还可以直接在所要执行的命令前面直接加上screen,这样跟直接screen然后执行命令一样,新窗口也没有名字。
screen ping 192.168.1.1
在linux中screen终端的记录只有一个窗口大小,没法往上翻记录,使用下面方法保留历史记录:
screen -L
4、会话分离
如果像关闭终端干别的事,就需要会话分离。
在当前的new_sceen窗口,ctrl+a,进入命令模式,然后ctrl+d即可退出当前窗口。
或者在新建的终端执行
screen -d threadnum
也可以分离这个窗口。
5、重连
screen -ls
可以查看所有screen窗口,然后选择需要连接的窗口,执行:
screen -r threadnum
6、杀死窗口
kill -9 threadnum
即可杀死进程和窗口。
或者ctrl+a然后ctrl+k杀死当前窗口和窗口中运行的程序。
screen -wipe
自动清除死去的窗口。