Screen tool usageTo put it simply, Screen is a window manager that can reuse a physical terminal among multiple processes. Screen has the concept of session. You can create multiple screen Windows in one screen session, just like operating a real telnet/SSH connection window in each screen window. There are several ways to create a new window in screen:
1. Directly type the screen command in the command line.
[root@tivf06 ~]# screen
Screen creates a full Screen window for executing shell. You can execute any shell program, as in the ssh window. In this window, type exit to exit the window. If this is the only window of the screen Session, the screen session will exit; otherwise, the screen will automatically switch to the previous window.
2. The Screen command is followed by the program you want to execute.
[root@tivf06 ~]# screen vi test.c
Screen creates a single window session for executing vi test. c. Exit vi and exit the window/session.
3. Create a screen session in both of the preceding methods. We can also create a new window in an existing screen session. In the current screen window, type C-a c, that is, Ctrl + a, and then press c. screen generates a new window in the session and switches to the window.
Screen also has more advanced features. You can temporarily disconnect (detach) the screen session without interrupting the running of the program in the screen window, and re-Connect (attach) The session at a later time to re-control the program running in each window. For example, open a screen window to edit the/tmp/abc file:
[root@tivf06 ~]# screen vi /tmp/abc
After that, we want to temporarily exit and do something else, such as going out for a walk, then type C-a d in the screen window, and Screen will display the detached prompt:
Temporarily interrupt session
After half an hour, I came back and found the screen session:
[root@tivf06 ~]# screen -lsThere is a screen on: 16582.pts-1.tivf06 (Detached)1 Socket in /tmp/screens/S-root.
Reconnect session:
[root@tivf06 ~]# screen -r 16582
Let's see what happened. It's great. Everything is there. Continue.
You may notice that a special key combination C-a is used to send commands to screen. This is because the information we typed on the keyboard is directly sent to the current screen window, you must use other methods to send a command to the screen window manager, by default, screen receives commands starting with C-. This command form is called key binding in screen, and C-a is called command character ).
You can use "C-? "To view all key bindings. common key bindings include:
C-? Show all key binding information C-a w show all windows List C-a switch to the previously displayed window C-a c create a new shell window and switch to this window c-a n switch to the next window C-a p switch to the previous window (relative to C-a n) c-a 0 .. 9 switch to window 0 .. 9C-a a sends C-a to the current window C-a d temporarily disconnects the screen Session C-a k to kill the current window C-a [enters the copy/rollback Mode
Screen common optionsUse the key to bind C-? The default Command key is C-a, and the Escape Character C-a (literal ^ a) is:
Because screen regards C-a as the beginning of the screen command, if you want the screen window to receive the C-a character, enter C-. Screen also allows you to use the-e Option to set your own command characters and escape characters. The format is:
-Exy x is the command character and y is the character of the escape command character
The screen session started by the following command specifies that the command character is C-t, and the escape C-t character is t, through C-t? Command to see the change.
[root@tivf18 root]# screen -e^tt
Custom command characters and escape charactersOther common command options include:
-C file: Use the configuration file instead of the default $ HOME /. screenrc-d |-D [pid. tty. host] does not enable a new screen session, but disconnects other running screen sessions-h num specifies that the historical rollback buffer size is num row-list |-ls to list existing screen sessions, the format is pid. tty. host-d-m starts a session in disconnected mode-r sessionowner/[pid. tty. host] reconnects to a disconnected session. In multi-user mode, you must specify the sessionowner to connect to screen sessions of other users, setuid-root permission-S sessionname is required to specify a name for the session when the screen session is created-v displays the screen version information-wipe [match] Same-list, but deletes sessions that cannot be connected
In the following example, two screen sessions in the detached state are displayed. You can use screen-r <screen_pid> to reconnect to the screen:
[root@tivf18 root]# screen –lsThere are screens on: 8736.pts-1.tivf18 (Detached) 8462.pts-0.tivf18 (Detached)2 Sockets in /root/.screen.[root@tivf18 root]# screen –r 8736
If one of the sessions is unexpectedly terminated for some reason, screen-list displays the session as dead. Run the screen-wipe command to clear the session:
[root@tivf18 root]# kill -9 8462[root@tivf18 root]# screen -ls There are screens on: 8736.pts-1.tivf18 (Detached) 8462.pts-0.tivf18 (Dead ???)Remove dead screens with 'screen -wipe'.2 Sockets in /root/.screen.[root@tivf18 root]# screen -wipeThere are screens on: 8736.pts-1.tivf18 (Detached) 8462.pts-0.tivf18 (Removed)1 socket wiped out.1 Socket in /root/.screen.[root@tivf18 root]# screen -ls There is a screen on: 8736.pts-1.tivf18 (Detached)1 Socket in /root/.screen.[root@tivf18 root]#
The-d-m option is an interesting partner. They start a session in disconnected mode. You can connect to the session as needed later. Sometimes this is a very useful function. For example, we can use it to debug background programs. This option is more commonly used:-dmS sessionname
Start an initial disconnected screen session:
[root@tivf06 tianq]# screen -dmS mygdb gdb execlp_test
Connect to this session:
[root@tivf06 tianq]# screen -r mygdb
Manage your remote sessionsLet's take a look at how to use screen to solve the SIGHUP problem. For example, we want to transfer a large file over ftp. If you follow the old method, log on to the system via SSH and run the ftp command to start transmission .. If the network speed is okay, congratulations, you don't have to wait too long. If the network is not good, wait honestly. You can only disconnect the SSH connection after the transmission is complete. Let's try using screen.
Log on to the system through SSH and Type screen in the command line.
[root@tivf18 root]# screen
In the screen shell window, enter the ftp command, log on, and start transmission. Don't you want to wait? OK. In the window, type C-a d:
Manage your remote sessions
Then .. Log out of SSH? As you do, just don't kill the screen session.
Is it convenient? Furthermore, we can use screen to manage your remote sessions and save all your work content. Do you have to open many windows every time you log on to the system, and then open them again every day? Let screen help you "save". You only need to open an ssh window and create a screen window. When you exit, C-a d will "save" your work, after the next login, you can directly use screen-r <screen_pid>.
It is better to give a name for each window so that you can remember it. Use C-a A to name the window. Use C-a w to view the names of these windows. The names may appear in different positions.
Use putty:Use telnet:More Screen FunctionsScreen provides rich and powerful customization functions. You can configure the files/etc/screenrc and $ HOME/by default in Screen /. specify more in screenrc, such as setting screen options, customizing binding keys, setting screen session self-start Windows, enabling multi-user mode, and customizing user access permission control. If you want to, you can also specify the screen configuration file.
Taking the multi-user function as an example, screen runs in single-user mode by default. You need to specify multiuser on in the configuration file to enable multi-user mode, through acl * (acladd, acldel, aclchg ...) command, You can flexibly configure other users to access your screen session. For more information about the configuration file, see the man page of screen.
From: http://www.ibm.com/developerworks/cn/linux/l-cn-screen/
Address: http://www.linuxprobe.com/screen-remote-use.html