How to use the Linux screen to multitask

Have you ever encountered a situation where when you run a long-term command over SSH, e.g. B. installing a desktop, suddenly the Internet connection on the computer was interrupted and the command did not complete automatically.
Of course, such an incident will make the mind dizzy, but know that there is a way to run the command so it will keep running without being disrupted by the client’s internet connection again. That’s with the order screen on Linux.
Screen or GNU screen Multiplexer terminal. Or in other words, you can run commands on Linux more than 1 session (Multitasking). Processes running on the screen will continue to run even if the client connection is lost and the session is still able to continue.
How do I install the Linux screen?
For most Linux operating systems like Ubuntu and Debian, Screen is installed by default, so it doesn’t need to be reinstalled. And to find out if Screen is installed, just enter the command screen --version
and later the current screen version will be displayed.
However, if it turns out that Screen is still not installed, please install it first using the following command:
Ubuntu and Debian
sudo apt install screen
CentOS & Fedora
sudo yum install screen
How to run the Linux screen
There are two ways to run Linux Screen, the simplest one, directly with this command:
screen
Meanwhile, the second method is pretty simple too, you can just give the session a name by following the command:
screen -S namasesi
Just change “Session name”As desired to recognize the meeting. And once a new session is created you will get all the commands that can be used by pressing the button CTRL+A+?
on the keyboard
Sign out of the screen session
Take off or do Peel off will not affect the tasks currently being performed in the session. And to share it, just press the following key on your keyboard:
CTRL+A+D
In essence, this does not end the current session, it only releases it.
Also read: Executing Commands Simultaneously on Multiple Linux Servers
Resume the screen session
After sharing a session, you can still view the tasks performed in that session. All you need to do is use the following command:
screen -r
However, of course, if you are running a lot of sessions, the above command will not work. And what to do is show all ongoing sessions on the Linux screen with the following command:
screen -ls
And the result will look like this:
There are screens on: 7699.pts-0.blogsecond-desktop (Detached) 8300.pts-0.namasesi-desktop (Detached)2 Sockets in /run/screens/S-blogsecond.
If you want to continue the session 7699.pts-0, just use the following command:
screen -r 7699
The easiest way to use the Linux screen
If the above method still seems difficult, this is the easiest way to use Linux Screen:
Enter the command in Terminal / SSH
screen
Now execute any command, for example to install a program.
End the session by pressing the button
CTRL
+A
+D
on the keyboard.To check again whether the task is complete or not, just enter the command
screen -r
Not the hard way, right? And this is perfect for those of you who frequently perform a task that takes a long time to complete, such as: B. installing Ubuntu desktop or downloading a file via wget.
There is much more to learn about Screen now, and all of this can be found on the GNU Screen Guide page. If you have any questions about the tutorial above, please feel free to leave a comment.
Hopefully useful and good luck