blog posts

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 if you want to become a professional Sysadmin, don’t underestimate the It.

It may seem a bit difficult initially, but Linux Screen is easy to learn. It also 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, Screen divides a physical terminal into several virtual sessions and stops and summarizes the activity in them.

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 access the Terminal again, 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: instead of a username and the server, enter your server’s IP.

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 this 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 in 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 that you can easily access it next time and not forget it.

Linux Screen uses specific commands to multiplex the Terminal and the commands are easy to learn. They all follow a Ctrl+* * structure where * are the same variables.
[highlight color=” yellow”]Important note: 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 need to learn how to work with it. Some of the main commands we deal with:

  • Create a new window: Ctrl+a c
  • 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 great 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 both CTRL+a and CTRL+d to detach the run from the Terminal. From here you can work on something else 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 how to install and use Linux Screen is very important, especially if you work as a server administrator. 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.