gnu screen的用法
在使用ssh或者telnet登錄遠程主機后執行一些耗時的命令, 如果此時ssh或者telnet中斷, 那么遠程主機上正在執行的程序或者說命令也會被迫終止.
screen能夠很好地解決這個問題, screen也叫虛擬終端, 可以在一個物理終端上實現多個虛擬終端的效果.
創建screen會話
# 新建一個screen screen # 新建一個screen并指定名稱 screen -S XXX以上命令, screen將創建一個執行shell的全屏窗口。你可以執行任意shell程序,就像在ssh窗口中那樣。在該窗口中鍵入exit退出該窗口,如果這是該screen會話的唯一窗口,該screen會話退出,否則screen自動切退到前一個窗口。
# screen命令后跟你要執行的程序。 screen vi test.cscreen創建一個執行vi test.c的單窗口會話,退出vi將退出該窗口/會話
以上兩種方式都創建新的screen會話。
在一個已有screen會話中創建新的窗口。在當前screen窗口中鍵入Ctrl + A, C,即Ctrl鍵+a鍵,之后再按下c鍵,screen 在該會話內生成一個新的窗口并切換到該窗口
斷開(detach)screen會話,并重連(attach)會話
#打開一個screen窗口編輯/tmp/abc文件: screen vi /tmp/abc之后暫時退出做點別的事情,在screen窗口鍵入Ctrl + A, D,Screen會給出detached提示, 這時候可以在命令行執行其他命令
# 半個小時之后回來了,找到該screen會話: screen -ls There is a screen on:16582.pts-1.tivf06 (Detached) 1 Socket in /tmp/screens/S-root. # 重新連接會話 screen -r 16582這時候會顯示出原來screen會話中的信息.
如果原screen還是Attached的狀態, 需要用 -x 參數
# 重新連接一個還在Attached狀態的screen session screen -x 16582?
screen的組合鍵操作列表
Ctrl-a ? 顯示所有鍵綁定信息 Ctrl-a w 顯示所有窗口列表 Ctrl-a C-a 切換到之前顯示的窗口 Ctrl-a c 創建一個新的運行shell的窗口并切換到該窗口 Ctrl-a n 切換到下一個窗口 Ctrl-a p 切換到前一個窗口(與C-a n相對) Ctrl-a 0..9 切換到窗口0..9 Ctrl-a a 發送 C-a到當前窗口 Ctrl-a d 暫時斷開screen會話 Ctrl-a k 殺掉當前窗口 Ctrl-a [ 進入拷貝/回滾模式screen命令的參數
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.?
總結
以上是生活随笔為你收集整理的gnu screen的用法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 简单工厂模式(Simple Factor
- 下一篇: springboot定时任务处理