I. BACKGROUND
System administrators often require SSH or telent telnet to a Linux server and often run tasks that take a long time to complete, such as system backups, FTP transfers, and so on. Usually we open a remote terminal window for each of these tasks because they take too long to execute. Must wait for them to complete, during this period cannot shut down the window or disconnects, otherwise this task will be killed, all halfway.
Second, Introduction
GNU Screen is a free software developed by the GNU Program for command-line terminal switching. The software allows the user to connect multiple local or remote command lines simultaneously and freely switch between them.
GNU screen can be viewed as a command-line interface version of the window manager. It provides a unified interface for managing multiple sessions and corresponding functions.
-
as long as the screen itself is not terminated, the session running inside it can be resumed. This is particularly useful for users who log on remotely-even if the network connection is interrupted, the user will not lose control of the command line session that has already been opened. Once you log on to the host again, execute
screen-r to resume the session's operation. Also at the time of the temporary departure, you can perform separate command
detach, in order to ensure that the program inside the case of the normal operation of the screen hangs (switch to the background). This is similar to VNC under the graphical interface.
-
in the screen environment, all sessions run independently and have their own numbering, input, output, and window caches. The user can switch between different windows with shortcut keys, and can freely redirect the input and output of each window. Screen implements basic text operations, such as copy-and-paste, and also provides a scroll bar-like feature to view the history of the window's status. Windows can also be partitioned and named, and can also monitor the activity of background windows.
Screen allows
-
one or more users to log in to a session multiple times from different terminals and share all the features of the session (for example, you can see the exact same output). It also provides a mechanism for window access to password-protect windows.
GNU ' s screen official site: http://www.gnu.org/software/screen/
Third, grammar
# screen [-amrvx-ls-wipe][-d < job name >][-h < number of lines >][-r < job name >][-s][-s < job name;]
Parameter description
-A adjusts all windows to the current size of the terminal.
-D < Job name > take the specified screen job offline.
-H < number of rows > specifies the number of buffer rows in the window.
-M forces a new screen job to be established even if the screen job is currently in operation.
-R < Job name > Restore offline screen jobs.
-R first attempt to recover the offline job. If you cannot find an offline job, create a new screen job.
-s Specifies the shell to execute when a new window is created.
-S < job name > Specifies the name of the screen job.
-V Displays version information.
-X the screen job is offline before recovery.
-ls or--list displays all of the current screen jobs.
-wipe checks all current screen jobs and removes screen jobs that are not already available.
Four, commonly used screen parameters
Screen-s Yourname, a new session called Yourname
Screen-ls, List all current session
Screen-r yourname, back to yourname this session
screen-d yourname, remote detach a session
Screen-d-R Yourname End the current session and return to the session Yourname
under each screen session, all commands start with Ctrl + A (C-A).
C-a? Show all key binding information
C-a C-Create a new window to run the shell and switch to that window
C-a N-Next, switch to the next window
C-a P---Previous, switch to the previous window
C-a 0..9, switch to the first 0..9 window
CTRL + A [Space], from Windows 0 sequential switch to Windows 9
C-a c-a, switching between the two most recently used Windows
C-a x, lock the current window and unlock it with the user's password
C-a D-Detach, temporarily leave the current session, the current screen session (may contain multiple windows) to the background to execute, and will return to the status of not yet in screen, at this time in the screen session, each W The process running within the Indow (either foreground/background) continues to execute, even if logout is not affected.
C-a Z, put the current session in the background, and use the Shell's FG command to go back.
C-a W-Show All Windows list
C-a T-time, showing the current times, and the system's load
Kill window, C-a K, forcibly closes the current window
c-a [, enter copy mode, can be rolled back, searched, copied in copy mode as if using 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 lower left corner
0 move to the beginning of the line
$ End of line
W forward one word, move forward in words
b Backward One word, move backward in words
Space is first pressed as the starting point for the marked area, and the second press is the end point
ESC ends Copy Mode
C-A], Paste, paste the content you just selected in copy mode
V. Use of screen
5.1 Installing screen
A popular Linux distribution, such as Red Hat Enterprise Linux, usually comes with the screen utility, and if not, it can be downloaded from the official website of the GNU screen.
[[email protected] ~]# yum install screen[[email protected] ~]# rpm-qa|grep Screenscreen-4.0.3-4.el5[[email protected] ~] #
5.2 Creating a new window
Once the installation is complete, you can start it by tapping the command screen directly. However, this startup screen session does not have a name, in practice it is recommended to take a name for each screens session, convenient to distinguish:
When screen starts, the first window is created, which is the window No. 0, and in which a system default shell is opened, it will generally be bash. So after you typed the command screen, you immediately returned to the command prompt, as if nothing had happened, but you have entered the world of screen. Of course, you can also add your favorite parameters after the screen command to open the program you specified, for example:
[Email protected] ~]# Screen VI david.txt
Screen creates a single-window session that executes VI david.txt, and exiting VI exits the window/session.
5.3 Viewing window and window names
After you open multiple windows, you can use the shortcut key C-a W to list all current Windows. If you use a text terminal, the list is listed in the lower left corner of the screen, and if you use the terminal emulator in the X environment, the list is listed in the title bar. The window list looks like this:
0$ bash 1-$ bash 2*$ bash
In this example, I opened three windows, where the * number indicates that the window 2,-is currently in window 1 when the last time the window was toggled.
Screen is named by default as a combination of the number and the name of the running program in the window, which is the default name in the example above. Practice the method of viewing the window above, you may want to have different names for each window to make it easy to distinguish. You can use the shortcut key c-a A To rename the current window, press the shortcut key, screen will allow you to enter a new name for the current window, return to confirm.
5.4 Session Separation and recovery
You can temporarily disconnect (detach) a screen session without interrupting the program running in the screens window, and reconnect (attach) The session at a later time to regain control of the programs running in each window. For example, we open a screen window to edit the/tmp/david.txt file:
[Email protected] ~]# screen Vi/tmp/david.txt
Linux Screen Command detailed