screen命令的使用

 平常開一個putty遠程登錄,經常需要在兩個程序之間來回切換,怎麼辦?ctrl-z和fg、bg?這些太麻煩了。其實我們可以藉助linux下的screen命令來實現輕鬆便捷的切換。

————————————————————————————————————


screen 命令的package 是screen.i386,如果系統內沒有安裝,可以用yum進行安裝後再使用。
1. yum查找當前的系統使用的screen包
[root@excast82 ~]# yum list screen
Installed Packages
screen.i386                              4.0.3-1.el5            installed      
Available Packages
screen.i386                              4.0.3-1.el5_4.1        updates        

2. 用yum安裝screen包
yum install screen*

3. screen 作用
Screen可以使用一個終端窗口處理多個服務器進程的操作,並且不會使操作中斷。例如我們需要運行一個case很久,但是又要關閉這個終端窗口或者關閉終端的機器;那麼用screen可以解決這個問題。我們用終端登錄到server上,然後啓動一個screen終端窗口,運行case,退出screen窗口,退出終端。下次我們再次進入screen窗口時,還可以看到上次進入的時啓動的case的運行狀態,就像是窗口一直沒有關閉一樣。

4. 經常用的 screen 命令


一般情況下,都需要我們用Screen命令下創建多個段,每個段中再創建多個窗口。

screen -S session名:創建一個新的段
screen -r session名:重新登錄一個段

screen -ls :查看所有的段

進入段後,使用Ctrl+A  * 對段進行操作:

Ctrl+A  d 退出當前的段

Ctrl+A  c -> Create,開啓新的 window
Ctrl+A  n -> Next,切換到下個 window
Ctrl+A  p -> Previous,前一個 window
Ctrl+A  Ctrl+A  -> Other,在兩個 window 間切換
Ctrl+A  w -> Windows,列出已開啓的 windows 有那些
Ctrl+A  0...9 -> 切換到第 0 ...9個 window
Ctrl+A  a -> 發出 C-a,在 emacs, ve, bash, tcsh 下可移到行首
Ctrl+A  t -> Time,顯示當前時間,和系統的 load
Ctrl+A  K(大寫) -> kill window,強行關閉當前的 window
Ctrl+A  [ -> 進入 copy mode,在 copy mode 下可以回滾、搜索、
複製就像用使用 vi 一樣
Ctrl-b Backward,PageUp
Ctrl-f Forward,PageDown
H(大寫) High,將光標移至左上角
L Low,將光標移至左下角
0 移到行首
$ 行末
w forward one word,以字爲單位往前移
b backward one word,以字爲單位往後移
Space 第一次按爲標記區起點,第二次按爲終點
Esc 結束 copy mode
C-a ] -> Paste,把剛剛在 copy mode 選定的內容貼上
C-a ? -> Help,顯示簡單說明
C-a d -> detach,將目前的 screen session (可能含有多個 windows)

5. screen 各個參數

[sherry@docomo6 ~]$ screen -help
Use: screen [-opts] [cmd [args]]
or: screen -r [host.tty]

Options:
-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.02 (FAU) 5-Dec-03".
-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.


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章