What is Linux screen? How to install It
Sysadmins usually manage virtual servers using the Linux terminal. However, you can get more out of Terminal by implementing Linux Screen into your workflow. Linux Screen is a favorite among professional developers, so don’t underestimate it if you want to become a professional Sysadmin.
Although it may seem a bit difficult initially, Linux Screen is easy to learn and offers unlimited possibilities. It is a very useful management tool; after using it, you don’t need to look for an alternative.
With this in mind, we will teach you how to enable and use Linux Screen to increase the flexibility of the Linux terminal.
What is a Linux screen?
Linux Screen is a terminal program developed by the GNU. Many official sources call it GNU Screen, which is used for terminal multiplexing.
In other words, the Screen divides a physical terminal into several virtual sessions, stops it, and summarizes the activity.
This is how it works: if you’re working in a terminal session while using Screen, it’s saved at that point when you’re done, and you shut down the computer. When you reaccess the Terminal, the Terminal will return to the Screen you were working on before the shutdown.
How to install Linux screen?
Don’t worry whether Linux Screen will be installed on your Linux distribution. Because it has been tested on most distributions and works well
First, we need to connect to our server using the SSH command. Open your Terminal and type the following command:
Note: Enter your server’s IP instead of a username and the server.
ssh username@server
If your Linux distribution is Debian, Ubuntu, or Linux Mint, enter the following command:
Sudo apt install screen
But if your Linux distribution is CentOS, enter the following command:
Sudo yum install Screen
Or, if the user can’t run Sudo commands, we need to run it as a root user:
Yum install Screen
At the end of the installation, we can check the current version of Linux Screen using the following command line:
screen-version
The process of installing the Linux screen is finished with ease. You can use it from now on.
Using Linux Screen in all Linux distributions
To run Linux Screen, type the following in your Terminal:
screen
After pressing the space key, you will see the Terminal again. Do not worry. Just type exit and press Enter.
Now we can start a session and name it using the -S variable. For example:
screen -S session1
It is better to give it an understandable name so you can easily access it next time and not forget it.
Linux Screen uses specific commands to multiplex the Terminal, which are easy to learn. They all follow a Ctrl+ *** structure where * are the same variables.
[highlight color=” yellow”] The Linux Screen is case sensitive. So be careful when entering commands.[/highlight]
Working with Linux screen in a new session
Now that we have created a new session, we must learn how to work with it. Some of the main commands we deal with:
- Create a new window: CCtrlc
- List of all created windows: “Ctrl+a.”
- Delete a Ctrl+a, which is useful in case of a mistake: Ctrl+a a
- Leave running session: Ctrl+a Ctrl+d
It is also possible to split the terminal Screen. For example, using Ctrl+a S splits the Terminal horizontally:
To switch to the next Terminal, press CTRL+a TAB. Press CTRL+a X to close it.
How to manage multiple sessions using the Linux screen
One of the great features of Screen is that it can leave ongoing actions in the background. So that when we return to them, they are still running. This feature is excellent for server administrators.
I will use htop for this example. With the following command, we can install it on Debian, Ubuntu, Linux Mint, etc.:
sudo apt install htop
You can then run htop by typing the following command in your Terminal:
htop
Next, we’ll use CTRL+a and CTRL+d to detach the run from the Terminal. You can work on something else from here while the previous window runs in the background. If you want to open the same htop Terminal, first type the following command:
screen -ls
It shows all your saved sessions. To reopen htop, enter the following command:
screen -r process_number
Here, for example, our process_number is 11520
Conclusion
Learning to install and use Linux Screen is very important, especially if you work as a server administrator. It is a very useful tool that can greatly improve your overall performance. Here, you learned how to install Screen on your server and how to use its basic commands.