在Windows中可以通过Putty来管理和访问Linux系统的SSH环境,运行命令返回结果。但由于一些不稳定因素,比如网络突然中断或不小心误关闭Putty窗口,就会导致远程命令也会被停止。如何避免这种情况,就要用到screen这个工具了。
1、screen是什么
screen是一个可以在多个进程之间多路复用一个物理终端的全屏窗口管理器。用户可以在一个screen会话中创建多个screen子会话,在每一个screen会话(或子会话)中就像操作一个真实的telnet/SSH连接窗口。
2、screen如何安装
一般最小化安装的Linux系统中默认是没有安装screen的。
Fedora / Centos系统:
yum -y install screen
Debian / Ubuntu系统:
apt-get -y install screen
3、screen如何使用
运行screen -help命令可以看到screen的具体用法如下。
Use: screen [-opts] [cmd [args]] or: screen -r [host.tty] Options: -4 Use IPv4. -6 Use IPv6. -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. -list or -ls. Do nothing, just list our SockDir. -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. -r 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.00.03 (FAU) 23-Oct-06". -wipe Do nothing, just clean up SockDir. -x Attach to a not detached screen. (Multi display mode). -X Execute <cmd> as a screen command in the specified session.
这里举例创建会话的用法。
screen -S lamp
以上命令是创建一个名为lamp的会话。在此会话中安装lamp一键安装包,是不会受网络中断影响的。
如果此时网络中断或关闭了Putty窗口,只需运行:
screen -r lamp
即可恢复原来的会话。
更多详细帮助,请执行man命令后参照。
man screen
转载请注明:秋水逸冰 » Linux远程登录命令screen