Instructions for using Screen on Linux
I. Introduction
You are administering a remote Linux system via SSH, in some cases your system is running a process and it takes a lot of time but you have to leave the office and you still want to go home. keep track of the progress. At this point you will need to use a software called Screen, a software that most Linux admins use and find very useful. So what is Screen software?
Screen, also known as GNU Screen, is a terminal multiplexer. In other words, it means you can start a connected session and then open any number of windows (virtual terminals) inside that session. Processes running in that session will continue to run even if our window is disconnected. And you can completely name these connections so that you can reconnect at any time.
To know how to use Screen on Linux, please see the next part of the article.
II. Using Screen on Linux
To use Screen on Linux we follow these 3 steps.
Step 1: SSH into your Linux system
To use Screen on Linux, the first thing we need to do is SSH into your VPS or server first. If you do not know how to SSH into your VPS or Server
- After successfully SSHing , we continue with step 2 to perform the test commands and install Screen.
Step 2: Check if there is a Screen on Linux
First you need to determine if the screen program is installed on your system. Currently, most Linux operating systems such as Redhat and CentOS, the screen program is usually pre-installed in the directory: /usr/bin/screen . To determine if Screen is installed on your system, use the following command:
which screen
If the returned result looks like this, the system already has a screen preset:
/usr/bin/screen
Otherwise, if not installed, it will be as follows and we must continue to run the installation command:
/usr/bin/which: no screen in (/root/exec -l /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin)
Step 3: Install Screen on Linux
If you are using CentOS or Fedora then you can use the following command to install.
sudo yum install -y screen
If you are using Ubuntu or Debian , you can use the following command to install.
sudo apt update sudo apt install screen
After installation we can use the following command to check the installed version of screen.
screen --version
Here are my results.
Step 4: Use Screen on Linux
Once installed on the system, use the following command to create a screen window inside a terminal as follows:
screen
If you want to name the screen window for easy management, use the following command:
screen -S name
With this command you can change “name” to the name you want.
You will now have a new window inside the terminal window. The interface of these two windows is the same, the difference is that screen allows you to use some commands from shortcut keys.
If you are interested in using these shortcuts, you can learn more
Exit Screen:
To exit the screen, you just need to turn off the SSH software or turn off the Terminal. This is the great advantage of screen, you can exit the screen and re-access it anywhere, while the commands in screen continue to work on the server. In the event of a sudden connection loss, screen automatically exits to keep your program safely running on the server.
List Screen List:
After exiting screen, want to know how many screen windows are running. From a terminal window, use the following command:
screen -ls
Continue using the previously created Screen:
In case you only have 1 screen you can quickly use the following command.
screen -r
In case there are multiple screens running, use the following command:
screen -ls screen -x name
With the first command to view the list, and command 2 to continue to the screen named “ name ”, this part will change if you have created a Screen with a different name.
Turn off the screen:
To turn off a Screen we use the command line below.
screen -S name -X quit
Remember to change the name to the Screen name you want to turn off.
Just like that, you already know how to use Screen on Linux to a sufficient level.