screen是linux下的一种多重视窗管理程序。在使用telnet或SSH远程登录linux时,如果连接非正常中断,重新连接时,系统将开一个新的session,无法恢复原来的session.screen命令可以解决这个问题。
简单的说,使用telnet或SSH远程登录linux时,如果连接非正常中断,重新连接时,系统将开一个新的session,无法恢复原来的session.screen命令可以解决这个问题。Screen工具是一个终端多路转接器,在本质上,这意味着你能够使用一个单一的终端窗口运行多终端的应用。
1、使用Screen 并不难,先安装该命令包是第一步:
Python1234[root@itchenyi~]# yum install -y screen[root@itchenyi~]# rpm -qa | grep screenscreen-4.0.3-16.el6.x86_642、安装完毕之后直接使用该命令(Screen)就可以打开Screen一个终端:
<a href="http://www.centoscn.com/uploads/allimg/131030/0035163644-0.jpg" class="cboxElement" rel="example4" 4442"="" style="text-decoration: none; color: rgb(1, 150, 227); ">
使用Screen命令
3、我们可以在Screen的终端中执行各种编译或其他复杂的工作,可以有效避免远程ssh 中断掉,同时也保障了ssh工作的稳定,如果需要暂时离开i啊Screen ,先按Ctrl+a,再按d即可,如果要直接退出Screen ,按Ctrl+d 即可,查看当前已打开的Screen 也很简单,如下:
Python12345[root@itchenyi~]# screen -lsThere are screens on:3779.pts-0.itchenyi(Detached)3791.pts-0.itchenyi(Detached)2Sockets in/var/run/screen/S-root.注:已经打开了两个screen会话。每一个screen会话都有一个编号,叫screen ID,如上面的3779 / 3791。
4、如果需要重新打开一个screen,则screen -r [ID number],如下:
Python1[root@itchenyi~]# screen -r 3779一些琐碎的帮助:
Python123456789101112131415161718192021222324252627282930313233343536[root@itchenyi~]# screen --helpUse:screen[-opts][cmd[args]]or:screen-r[host.tty]Options:-4Use IPv4.-6Use IPv6.-aForce allcapabilities 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'sname).-Tterm Use term as$TERM forwindows,rather than"screen".-UTell screen to use UTF-8encoding.-vPrint"Screen version 4.00.03 (FAU) 23-Oct-06".-wipe Do nothing,just clean up SockDir.-xAttach toanotdetached screen.(Multi display mode).-XExecute<cmd>asascreen command inthe specified session.