linuxscreencommand命令及示例.docx
《linuxscreencommand命令及示例.docx》由会员分享,可在线阅读,更多相关《linuxscreencommand命令及示例.docx(15页珍藏版)》请在冰豆网上搜索。
linuxscreencommand命令及示例
本文包含两部分。
第一部分虽然是整理来的英文资料,但平时搜索不容易搜索到,所以还是比较有价值的,是关于多路利用终端软件详解和比较的http:
//hyperpolyglot.org/multiplexers,然后把自己不关心的tmux部分删除后,只留下screen的部分。
第二部分针对原文命令行参数部分的不足增加了完整的help,并增加了一个sipP测试的例子。
本人其实只关心原文的screencommand那一列,因为从命令行help无法获取这一部分信息,而我一起在苦苦查找这部分资料,它对以编程的方式控制screen是非常重要的参考,使在无人值守的情况下(如定时或在系统崩溃重新启动后)自动创建一个有多window的screen并启动若干后台测试成为可能。
1.Terminology
server|client|session|window|region|pane
howsshworks:
Whenauserlogsintoaremotehostusingssh,thesshprocesscontactsansshdprocesslisteningonTCPport22.ThesshdprocessopensupanewTCPportandforksoffacopyofitselfforcommunicatingwiththesshprocess.Thenewportandchildprocessarefortheexclusiveuseoftheconnectionbeingestablished.
Thechildsshdprocessauthenticatesthesshprocess,andifitpassesitcreatesapseudo-terminal.Itthenforkstheremoteuser'sshellwhichbecomesthecontrollingprocessforthepseudo-terminal.
Ifthenetworkconnectionisclosed,eitherexplicitlybythesshprocessorbecauseofalossofnetworkconnectivity,thechildsshdprocessclosesthepseudo-terminal,andthisinturncausestheshelltoexit.
theSIGHUPproblem:
Iftheshellhadanyprocessgroupsrunningwhenitexits,theyaresentaSIGHUPsignalfollowedbyaSIGCONTsignal.BydefaultprocessesexitwhentheyreceiveSIGHUP.Thismakesitchallengingtorunlong-runningjobsonaremotehostwhenthenetworkconnectionisunreliable.
AsimplesolutiontotheSIGHUPproblemistoruneachjobwithnohup.Optionally,shellssuchasbashandzshhaveadisownbuilt-inwhichcanbeusedonaprocessthatisalreadyrunning,shouldtheuserhaveneglectedtorunitwithnohup.
Thefishshellwheninvokingaprocessinthebackgroundwith&setsthesignalhandlingstateoftheprocesstoignoreSIGHUP.Itwilldothesameiftheprocessissuspendedwith^Zandthenputinthebackgroundwithbg.
Multiplexersofferasolutionwhichprotectstheshellinsteadofthejob.Theuserdoesn'tneedtoremembertoruneachjobwithnohup.Asanaddedbenefitanystatekeptbytheshellispreserved.
server:
Themultiplexerservercreatespseudo-terminalswhichareusedforrunningandinteractingwithprograms.
ScreenandTmuxserverscancreatemultiplepseudo-terminals.Thecontrollingprocessforeachpseudo-terminalistheuser'sshell.
client:
Toseetheoutputofashelltheusermustconnecttothemultiplexerserverwithamultiplexerclientprocess.
Ifthemultiplexerisbeingrunonaremotemachineandtheuser'sconnectionislost,theserveranditsterminalsandcontrollingprocessespersist,buttheclientprocessexits.
Whenmultipleclientprocessesconnecttothesameservertheyseethesameoutput.Thisisawaytoshareadisplayacrosscomputers.
session:
Multiplexerssupportmultiplesessions.Eachmultiplexersessionhasitsownsetofterminalsandcontrollingprocesseswhichitisrunning.Theclientmustchooseasessiontoattachto,andwillonlybeabletoseetheoutputofthecontrollingprocessesinthatsession.Sessionscanbegivennamestomakeiteasyfortheclienttochoosethecorrectsession.
Screenlaunchesaseparateserverprocessforeachsession.Screenserversandclientscommunicatevianamedpipes.
Tmuxbydefaultwillonlyrunoneserverprocessperuser,andthisserverprocesscanhavemultiplesessions.ATmuxclientandtheservercommunicateviaaUnixdomainsocketinthe/tmpdirectory.The-Loptioncanbeusedtospecifyadifferentsocket;anewserveriscreatedforeachsocket.
window:
BothScreenandTmuxhaveentitieswhichtheycallwindows.
AScreenwindowhasasinglepseudo-terminalandshell.ATmuxwindowcanhavemultiplepseudo-terminalsandshells.
Screenwindowscansharetheviewport.TheTmuxviewportcanonlydisplayonewindowatatime.
BothScreenandTmuxwindowsarenumberedstartingfromzero.
region:
Screencandividetheviewportintomultipleregions.
Screenregionscanbeemptyortheycancontainawindow.Thesamewindowcanbedisplayedinmorethanoneregion.Whenregionsshareawindowtheircontentisidentical.
Screenregionsarestackedontopofeachotherandextendthefullwidthofthewindow.
pane:
Tmuxcandividewindowsintomultiplepanes.
Tmuxpanescontainasinglepseudo-terminalwithashell,andeachpseudo-terminalandshellbelongstoonlyonepane.
Tmuxwindowscanbedividedbothhorizontallyandverticallyintopanes.Eachdivisioncanbesubdividedfurther.
Tmuxpanesarenumbered.
Tmuxpanescanbemovedbetweenwindows.
commandcharacter(prefix):
Multiplexerspassmostinputontotheshellintheregionwithfocus,butaspecialcommandcharacterisusedtosendcommandstothemultiplexer.
ThedefaultcommandcharacterinScreenisC-a.ThekeystrokeswhichfollowC-aareinterpretedbyScreeninsteadofbeingpassedtotheshell.
TmuxcallsthecommandcharactertheprefixandthedefaultvalueisC-b.ThekeystrokesfollowingtheprefixareinterpretedbyTmuxinsteadofbeingpassedtoshell.
scrollbackbuffer(history):
ScreenandTmuxkeepahistoryoftheoutputofeachshell.Themaximumlengthoftheoutputinlinesisconfigurable.
Screencallsthehistorythescrollbackbuffer.
copy/scrollbackmode(copymode):
ScreenandTmuxsupporttwomodesforeachregion.Indefaultmode,inputwhichisnotinterceptedbythemultiplexerispassedtotheshell.
Whentheregionisincopymodetheregionbehaveslikearead-onlybufferofaneditor.Thecontentsaretheoutputoftheshellincludingoutputthatmayhavescrolledoffthetopoftheregion.
ThekeybindingsusedbyScreenincopy/scrollbackmodeareVim-style.ItispossibletocustomizethemtobeEmacs-style.
TheTmuxcallscopy/scrollbackmodesimplycopymode.ThekeybindingsarebydefaultEmacs-style.
pastebuffer:
Screenhasasinglepastebuffer.
Tmuxhasmultiplepastebuffers.TheTmuxpastebuffersarenumbered;themostrecentisnumberzero.Sessionsshareacommonpastebufferhistory.
caption(statusline):
WhenaScreenwindowissplitintomultipleregions,acaptionlineisplacedatthebottomofeachregion.Whenawindowcontainsasingleregion,Screenbydefaultdoesnotdisplayacaption.Thecaption,whenpresent,containsinformationfromScreen.Theinformationthatisdisplayedcanbecustomized.
Tmuxcallsthelineatthebottomofawindowthestatusline.Bydefaultitisalwaysdisplayed,thoughitcanbeturnedoff.ThestatuslinecontainsinformationfromTmuxwhichcanbecustomized.
2.
KeyBindings
sessions|windows|regions|panes|pastebuffer|copymode
functoin
C-ashotcut
screencommand
help
?
:
help
sendprefixtoapp
a
:
meta
suspendmultiplexer
C-z
:
suspend
showpreviousmultiplexermessage
m
C-m
:
lastmsg
sourcefile
-
:
sourcefile
detach
d
C-d
:
detach
sessions
function
C-ashotcut
screencommand
newsession
-
-
newnamedsession
-
-
switchsession
-
-
renamesession
-
:
sessionnamefoo
killsession
C-\
:
quit
windows
function
C-ashotcut
screencommand
createnewwindow
c
C-c
:
screen
switchtonextwindow
n
C-n
SPACE
:
next
switchtopreviouswindow
p
C-p
BACKSPACE
h
:
prev
toggletolastwindow
C-a
:
other
selectwindown
-
-
listwindows
w
C-w
:
windows
showcurrentwindownumberandname
N
:
number
renumbercurrentwindow
-
-
movecurrentwindowtoanothersession
-
-
redrawcurrentwindow
l
C-l
:
redisplay
choosewindowinteractively
"
:
windowlist-b
renamewindow
A
:
title
selectwindowfoo
'
:
select
closecurrentwindow
C-k
:
kill
joinwindow1tocurrentwindow
-
-
joinregion0ofwindow1tocurrentwindow
-
-
regions
function
C-ashotcut
screencommand
splitintotopandbottomregions
S
:
split
movedowntonextregion
TAB
:
focus
makeregionssameheight
-
:
resize=
closecurrentregion
X
:
remove
closeallbutcurrentregion
Q
:
only
clearcurrentregion
C
:
clear
logregiontofile
-
fileisscreenlog.NN
:
log
turnofflogging
-
:
logoff
makecurrentregionnrowstaller/shorter
-
:
resize+n
:
resize-n
makecurrentregionnrowstall
-
:
resizen
pastebuffer
function
C-ashotcut
screencommand
entercopymode
[
C-[
ESC
:
copy
pastemostrecentbuffer
]
-
listbuffers
onlyonebuffer
-
choosebuffertopasteinteractively
-
-
writebuffertofile
writesto/tmp/screen-exchange:
>
:
writebufpath
copyfiletobuffer
copiesfrom/tmp/screen-exchange:
<
:
readbufpath
copymode
function
shotcut
screencommand
defaultbindings
Vim-style
setmark
SPACE
-
copyfrommarktopointandexitcopymode
whenmarkisset:
SPACE
-
singlecolumnmovement
alsoleftrightarrow
hl
-
singlelinemovement
alsodownuparrow
jk
-
beginningofline
0
-
endofline
$
-
forwardword
e
-
backwardword
b
-
pageup
C-b
-
pagedown
C-f
-
beginningofbuffer
g
-
endofbuffer
G
-
searchbackwards
?
phrase
-
searchforwards
/phrase
-
exitcopymode
anyunboundkeyalsoworks:
ESC
-
3.
Customization
funciton
configuration
startupfile
~/.screenrc
scrollbacklength
defscrollback2000
setprefix
howtosetprefixtoC-b,withasecondC-btosendaC-btothecontrollingprocess:
escape^B^B
definekeybinding
bind
undefinekeybinding
-
setcopy/scrollbackkeybindingstyle
vibindingsbydefault.
Whenredefining,usevi
commandsonleftofequations:
markkeysh=^B:
l=^F:
$=^E
disablestartupmessage
startup_messageoff
numberwindowsfromone
-
alwaysshowstatusbar
splitonlybydefault:
captionalways
captionsplitonly
customizecaption
captionstring"string"
captionescapes
function
configuration
shelloutput
firstargisanidentifierreferencedbythecaptionstring;
thesecondandth