Linux - CentOS7 the screen installation and command Detailed

Foreword


These days hesitation network problems when SSH remote login linux always interrupted abnormally, can not continue to just mission after logging on in the arrangements and the server, so [crash]. Not solve this problem I found it screen.

Brief introduction


When using telnet or SSH remote login linux, if the connection is interrupted abnormally, when you reconnect, the system will open a new session, can not restore the original session.screen command can solve this problem. Screen tool is a terminal multiplexer, in essence, this means that you can apply to use a single terminal window to run multiple terminals.

  • Session recovery

As long as Screen itself is not terminated, the session runs in its interior can be restored. This remote login is particularly useful for users - even if the network connection is interrupted, users will not lose control of the command-line session has opened the. Just log on again to perform screen -r host can resume running session. Similarly, when a temporary leave, can also perform separate command detach, let Screen suspend (switch to the background) in the case to ensure the normal operation inside the program. VNC at this point and the graphical interface is very similar.

  • Multi-window

Under Screen environment, all sessions are run independently and has its own serial number, input, and output window cache. Shortcut keys can be switched by the user in different windows, and can input and output redirection freedom of each window. Screen achieve the basic text operations, such as copy and paste, etc.; also provides a similar function scroll bar, you can view the status window of history. Partitions and windows can also be named, you can also monitor the activities of the background window.

  • Session Sharing

Screen allows one or more users logging in from a different terminal several times a session, and share all the characteristics of the session (for example, you can see exactly the same output). It also provides a mechanism to access the window, the window can be password protected.

GNU's Screen Official site: http://www.gnu.org/software/screen/

grammar


screen [-AmRvx -ls -wipe][-d <作业名称>][-h <行数>][-r <作业名称>][-s <shell>][-S <作业名称>]

Parameter Description


-A  将所有的视窗都调整为目前终端机的大小。
-d <作业名称>  将指定的screen作业离线。
-h <行数>  指定视窗的缓冲区行数。
-m  即使目前已在作业中的screen作业,仍强制建立新的screen作业。
-r <作业名称>  恢复离线的screen作业。
-R  先试图恢复离线的作业。若找不到离线的作业,即建立新的screen作业。
-s  指定建立新视窗时,所要执行的shell。
-S <作业名称>  指定screen作业的名称。
-v  显示版本信息。
-x  恢复之前离线的screen作业。
-ls或--list  显示目前所有的screen作业。
-wipe  检查目前所有的screen作业,并删除已经无法使用的screen作业。

Common screen parameters


screen -S yourname -> 新建一个叫yourname的session
screen -ls(或者screen -list) -> 列出当前所有的session
screen -r yourname -> 回到yourname这个session
screen -d yourname -> 远程detach某个session
screen -d -r yourname -> 结束当前session并回到yourname这个session

In each screen session, all commands begin with ctrl + a (Ca).

C-a ? -> 显示所有键绑定信息
C-a c -> 创建一个新的运行shell的窗口并切换到该窗口
C-a n -> Next,切换到下一个 window 
C-a p -> Previous,切换到前一个 window 
C-a 0..9 -> 切换到第 0..9 个 window
Ctrl+a [Space] -> 由视窗0循序切换到视窗9
C-a C-a -> 在两个最近使用的 window 间切换 
C-a x -> 锁住当前的 window,需用用户密码解锁
C-a d -> detach,暂时离开当前session,将目前的 screen session (可能含有多个 windows) 丢到后台执行,并会回到还没进 screen 时的状态,此时在 screen session 里,每个 window 内运行的 process (无论是前台/后台)都在继续执行,即使 logout 也不影响。 
C-a z -> 把当前session放到后台执行,用 shell 的 fg 命令则可回去。
C-a w -> 显示所有窗口列表
C-a t -> Time,显示当前时间,和系统的 load 
C-a k -> kill window,强行关闭当前的 window
C-a [ -> 进入 copy mode,在 copy mode 下可以回滚、搜索、复制就像用使用 vi 一样
    C-b Backward,PageUp 
    C-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 选定的内容贴上

Installation screen


[root@VM_183_120_centos ~]# yum install screen -y
[root@VM_183_120_centos ~]# rpm -qa|grep screen
screen-4.0.3-4.el5

Common Commands


1. Create a new session

The following command testis the name of a new session

[root@VM_183_120_centos ~]# screen -S test

2. Review existing session

[root@VM_183_120_centos ~]# screen -ls

3. Reconnect session (here we reconnection test)

[root@VM_183_120_centos ~]# screen  -r test //可以是名字test也可以是session ID

4. Exit session

[root@VM_183_120_centos ~]#screen -d  <session ID 或者 名字>

5. Clear the dead Session

If for some reason one of the sessions dead (e.g. human kill the session), then displays the session screen -list as the dead state. Use this command to clear the screen -wipe session

[root@VM_183_120_centos ~]#screen -wipe

6. Close or kill the window
under normal circumstances, when you exit a window the last program (usually bash) after the window is closed. Another method is to use Close Ca k, the shortcut keys kill the current window, but will also kill the process running in the window.

If a Screen session last window is closed, then the entire session will exit the Screen, screen process will be terminated.

In addition to turn to exit / kill the current session Screen all windows in this way, you can also use the shortcut Ca:, then enter the quit command to exit the Screen session. It should be noted that such exit will kill all windows and quit all programs running in it. In fact, Ca: This shortcut allows direct user input commands There are many, including a split screen can be split and other inputs, and this is a way to Screen functions are implemented, however personally believe it is relatively convenient shortcuts.

Published 44 original articles · won praise 11 · views 20000 +

Guess you like

Origin blog.csdn.net/LUCKWXF/article/details/104417919