
Recently I started taking notes on some commonly used commands and components so that I can find them when needed. What I want to record on my good VPS today is the screen command .
screen is a full-screen window manager that can multiplex a physical terminal between multiple processes. We can establish multiple sessions and keep them connected and running. To give a simple example, for example, when we are compiling lnmp0.9, what should we do if the computer needs to be shut down? What should I do if the network is suddenly disconnected? Do you have to waste all your efforts and start over again? No! At this time, using screen can solve these troubles.
1. Install screen
Let's take the VPS installation of CentOS system as an example. Some VPS systems of good VPS already come with screen, and some need to be installed.
yum install screen #Install screen
The installation is quick, usually only 1 minute, and after that, we can use it.
Below, we record some commonly used screen commands .
2. Create a remote session
Taking editing lnmp as an example, first, we create a screen session window and define the name of this window as lnmp
screen –S lnmp
Execute the above command and press Enter to automatically enter the new lnmp session window
. In this session window, we can start the process of compiling lnmp, such as downloading the script, decompressing it, and running the installation.
3. Temporarily leaving the session
After officially compiling lnmp, we know that this process takes a long time, ranging from ten minutes to several hours. At this time, we can leave this window, but we are Running stuff doesn't terminate.
Hold down Ctrl, and then press a and d on the keyboard in sequence to temporarily leave this session window and return to the main session. We can exit or do other things without affecting the previous compilation process.
4. Return to the session
As I just said, we have established a lnmp compiled session window. If we have exited the ssh login, then log in again and directly run the command to return to the previous session.
screen –r
Above, I only established one session. Assuming we have established multiple sessions, we can directly enter the specified session by adding the name or ID of the session window.
screen –r lnmp #Enter the session named lnmp
screen ls < x2> #List session ID
screen –r **** #** ** represents the ID number, directly enter the ID session
5. Other commands
screen runs in the background and still needs to consume certain system resources. At any time, after the work of a session window is completed, we exit (completely close) the session with the command exit. In addition, when multiple During the session, some other commands can help us.
Ctrl + a, d #Leave the current session
Ctrl + a, c <x2 > #Create a subsession in the current screen session
Ctrl + a, w #Subsession list
Ctrl + a, p #Previous subsession
Ctrl + a, n <x2 > #Next sub-session
Ctrl + a, 0-9 #Switch between the 0th window and the 9th sub-session
In short, the screen command is very helpful for us in the use of Linux VPS, especially for novice friends who use it. Multiple sessions can be opened simultaneously to perform different tasks, which can save a lot of time.