screen for the switching command line terminal

screen command

Screen is a program developed by the GNU free software for command-line terminal handover. The user can simultaneously connect a plurality of software by the local or remote command-line session, and freely switch between them. GNU Screen can be seen as a command line interface version of the window manager. It provides a unified interface and corresponding functionality to manage multiple sessions.

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 it 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. Screen sharing session 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 <Job name>] [- <line number> h] [- r <Job name>] [- S] [- S <Job name>]

======================================

Options

-A all the windows are adjusted to the size of the current terminal.

-d <job name> offline job specified screen.

Buffer lines -h <line number> specified window.

Even if -m has been in the job screen operation, the screen is still forced to create a new job.

-r <job name> to restore offline screen operation.

-R first attempts to restore offline operations. If the work can not be found offline, namely the establishment of a new screen work.

-s specified when creating a new window, shell to be performed.

-S <job name> Specifies the name of screen job.

-v display version information.

-x recovery screen work offline before.

-ls or --list show all current screen work.

-wipe screen to check all current jobs, and delete jobs has been unable to use the screen.

======================================

Common screen parameters

screen -S yourname -> Create a session called yourname

screen -ls -> lists all of the current session

screen -r yourname -> Back yourname this session

screen -d yourname -> Remote detach a session

screen -d -r yourname -> end the current session and return to the session yourname

======================================

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

Ca -?> To display all key bindings

Ca c -> Create a new run shell window and switch to that window

Ca n -> Next, switch to the next window

Ca p -> Previous, before switching to a window

Ca 0..9 -> switching to a window of 0..9

Ctrl + a [Space] -> 0 sequentially switched from window to window 9

Ca Ca -> switching between the two most recently used window

Ca x -> Lock the current window, the user password is required to unlock

Ca d -> detach, temporarily leave the current session, the current screen session (possibly containing a plurality of Windows)

Thrown into the background, and will return to the state when not into the screen, process screen session at this time, the operation of each window

(Either foreground / background) have continued to perform, even if the logout is not affected.

Ca z -> the current session into the background, with the fg command shell, you can go back.

Ca w -> to display a list of all windows

Ca t -> time, displays the current load time, and systems

Ca k -> kill window, forced to close the current window

Ca [-> to enter the copy mode, you can roll back in the copy mode, searching, copying the same as with the use of vi

C-b Backward,PageUp

C-f Forward,PageDown

H (uppercase) High, move the cursor to the upper left corner

L Low, move the cursor to the bottom left corner

0 to start of line

$ End of line

w forward one word, word units moved forward

b backward one word, word units moves back

Space as a starting point mark for the first time by region, for the second time by the end of

Esc end of the copy mode

Ca] -> paste, just put in copy mode selected content labeled

======================================

Use screen

Installation screen

Popular Linux distributions (such as Red Hat Enterprise Linux) usually comes with screen utility, if not, can be downloaded from the official website GNU screen.

[root@TS-DEV ~]# yum install screen

[Root @ TS-DEV ~] # rpm -qa | grep screen

screen-4.0.3-4.el5

[root@TS-DEV ~]#

Create a new window

After the installation is complete, hit command screen you can start it. But this does not start a screen session name, a name recommended practice session for each screen, easy to distinguish:

[root@TS-DEV ~]# screen -S david

After the screen starts, it will create the first window, which is the window No. 0, and which opens a system default shell, usually is bash. So, after you type the command screen, immediately returned to the command prompt, as if nothing had happened, in fact, you have entered the world of the Screen. Of course, you can also add your favorite commands after screen of parameters to directly open a program you, for example:

[root@TS-DEV ~]# screen vi david.txt

screen to create a single-window implementation of vi david.txt session, quit vi will exit the window / session.

======================================

Check windows and window name

After opening multiple windows, you can use keyboard shortcuts Ca w lists all the current window. If you use a text terminal, this list will be listed in the lower left corner of the screen, if you are using a terminal emulator under X environment, this list will be listed in the title bar. Window list looks generally like this:

0$ bash  1-$ bash  2*$ bash

I opened this example, three windows, where * represents the number of the window 2, the current - of the window 1 expressed on a number of switching windows.

Screen default window named for the number and the name of the program window, run the combination of the above example are the default window name. Practicing the method above to view the window, you may want each window may have a different name in order to facilitate the distinction. You can use shortcut keys to Ca A Rename the current window, press the shortcut key, Screen will allow you to enter a new name, press Enter for the current window.

======================================

Separation and Recovery Session

You can not interrupt the operation screen window program is temporarily disconnected (detach) screen session and reconnect at a later time (attach) the session to regain control program running in each window. For example, we open a screen window to edit /tmp/david.txt file:

[Root @ TS-DEV ~] # screen vi after /tmp/david.txt we want to do something else temporarily quit, such as go for a walk, then type Ca d in the screen window, Screen gives detached prompt:

Temporary interruption of the session

Half an hour later came back to find that screen session:

[root@TS-DEV ~]# screen -ls

Reconnect the session:

[Root @ TS-DEV ~] # screen -r 12865 everything.

Of course, if you do not have a Screen separate session on another machine, it is impossible to resume the session. Then you can use the following command to force the session in which it is separated from the terminal, transferred to the new terminal up:

Clear 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:

Close or kill the window

Normally, when you exit a window the last program (usually bash), this 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.

======================================

screen Advanced Applications

Session Sharing

There is also a more fun session recovery, session sharing can be achieved. Suppose you and a friend sign in to the same machine users in different locations, then you create a screen session, you can friend on his command in Terminal:

[Root @ TS-DEV ~] # screen -x This command will your friend's terminal Attach to your Screen session and your terminal will not be Detach. So you and a friend can share the same session, if you currently and in the same window, it is equivalent to sitting in the same front display will synchronize your presentation to your friend, your friend's operations will be synchronized presentation Give you. Of course, if you switch to a different window of the session to go, we can still carry out different operations, respectively.

Session locking and unlocking

Screen allows the use of keyboard shortcuts Ca s Lock Session. After the lock, then any input screen will no longer have to respond. But be aware that although the screen is not visible reaction, but your input will be received in the process to Screen. Shortcuts Ca q can unlock a session.

Ca x can also be used to lock the session, except that after such a lock, the session will be password-protected user belongs to Screen, you need to enter a password to continue accessing the session.

Send commands to the screen session

In addition to Screen session, a session can screen Screen command operation, which also increases the convenience to use Screen as a script program. Screen on the application in the script is beyond the scope of the entry, look at an example here to experience the operation of Screen outside the session:

[Root @ TS-DEV ~] # screen -S sandy -X screen ping www.baidu.com This command creates a new window in the screen in a session called sandy, and runs the ping command.

======================================

Split screen

Now the display is so big, dividing a screen into different regions show different Screen window is obviously a cool thing. You can use shortcut keys Ca S will split level display, after Screen 4.00.03 version, also supports vertical split-screen, shortcuts are Ca |. After the split screen, Ca can be used to switch between each of the blocks, you can create windows on each block and runs the process.

You can turn off the screen blocks currently focused with Ca X shortcuts, you can also use Ca Q Close all other blocks in addition to the current block. Close the window block and does not close, it may also be found through the window switch.

======================================

C / P mode operation and

Another screen is very powerful feature is the ability to copy and paste between the different windows. Use shortcut keys or Ca Ca [enter the copy / paste mode, this mode can be the same as in vi moving the cursor, the space key and sets a flag may be used. In fact this mode vi similar to the lot, such as the use / search, using fast tag line y, w quickly using a word like numerals. About Advanced operation in C / P mode, this part of the document which is a more detailed description.

In general, the cursor can be moved to a designated position, press the space provided at the beginning of a mark, and then move the cursor to the end position, a second press space mark, while the portion between two marks will be stored in the copy / paste buffer in, and exit the copy / paste mode. In the normal mode, you can use the shortcut Ca] stored in the buffer content is pasted into the current window.

 

======================================

More screen function

Like most UNIX programs, GNU Screen provide rich and powerful customization features. You can default to two-stage configuration file in Screen's / etc / screenrc and $ HOME / .screenrc specified in more, such as setting screen options, custom key bindings, set the screen window since the start of the session, to enable multi-user mode, customization user access control, etc. If you prefer, you can also specify screen configuration file yourself.

Multi-user functionality, for example, screen default is single-user mode, you need to specify the multiuser on in the configuration file to open the multi-user mode by acl * (acladd, acldel, aclchg ...) command, you can be flexible Configuring other users access to your screen session. More profiles please refer to the screen man page.

Guess you like

Origin www.cnblogs.com/cloudrivers/p/11707848.html
Recommended