How to Install and Use Linux Screen?

How to Install and Use Linux Screen?

Sysadmins generally manage virtual servers using the Linux terminal. However, you can get even more out of it by implementing the Linux Screen in your workflow. It’s a long-running favorite among developers and is a must for anyone who wants to become an expert.

It might seem intimidating at first, but the Linux Screen is easy to learn while providing limitless possibilities. It’s a very efficient and resourceful utility, making it an irreplaceable tool.

With this in mind, we will teach you how to enable and use Linux Screen to increase the flexibility of the Linux terminal further.

What Is Linux Screen?

A Linux Screen is a terminal application developed by the GNU project. Often official documentation calls it a GNU Screen and is used for terminal multiplexing.

In other words, Screen divides a physical terminal into multiple virtual sessions, stops and summarizes the activity in them.

Screen works like this – if you work on a terminal session while using Screen, once you’re finished with your work and turn off the computer, it will save at that point. When the terminal is reaccessed, the terminal will return to the very same screen you worked on before shutting down.

Linux Screen might be basic in its structure, but every Linux user should know how to use it.

How to Install and Use Linux Screen?

Screen is usually installed by default on all major Linux distributions. If your system doesn’t have it preinstalled, don’t worry, the installation process is easy.

First, we need to connect to our server using the SSH command. Open up your terminal and type:

ssh your-user@server

In the case of Debian, Ubuntu or Linux Mint and its derivatives, you can execute the following command:

sudo apt install screen

If you are using CentOS 7, you can install it using the following:

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 Screen, using the following command line:

screen –version

Congratulations, now you can finally use Screen.

Using Linux Screen on Any Linux Distribution

To run Linux screen, we just have to type the word in our terminal session:

screen
Running Linux Screen for the first time

After pressing the Space key, you will see the terminal again. Do not be worried, we have already started a new Screen session. To check it, just type exit in and press Enter.

So, we need to rerun the command by typing screen again.

We can also start a session and give it a name by using the -S variable. For example:

screen -S session1

We recommend you give the session a descriptive name and you will have no problem identifying it.

Screen uses commands to perform terminal multiplexing and the commands are easy to learn. They all follow a Ctrl+* * structure, where * are the variables.

Important! Take note of the lowercase and uppercase keys when performing commands.

Different Linux Screen commands

Working in a New Session

Once we have started a new session it is necessary to learn how to use it. These are the main commands you’ll be using:

CommandsDescription
Ctrl+a cCreate a new window
Ctrl+a ”List all the created windows
Ctrl+a aDelete a Ctrl+a, which useful if you made a mistake
Ctrl+a Ctrl+dLeave the session running

It is also possible to split the terminal screen. For example, using Ctrl+a S splits the terminal horizontally:

Splitting the terminal using Linux Screen

To change to the next terminal, we press CTRL+a TAB. To close it, CTRL+a X.

How to Manage Multiple Sessions Using Linux Screen

One of the great qualities of Screen is the ability to perform actions and leave them in the background so that when we return to them they’re still there. This is especially great for server administrators.

For this example, I will use htop. We can install it on Debian, Ubuntu, Linux Mint and its derivatives with the following command:

sudo apt install htop

You can run htop by simply typing the following command in your terminal:

htop
Using htop as an example for Linux Screen

Next, we will use both CTRL+a and CTRL+d commands to detach the execution from the terminal. From here you can work on something else, while the previous window will run in the background. If you want to open up the same htop terminal, first type in the following command:

screen -ls

It will show all of your saved sessions. To reopen htop, enter the following:

screen -r process_number
Reopening the previous session using Linux Screen

In this case, our process_number is 11520

Conclusion

It is really important to learn how to install and use Linux Screen, especially if you work as a server administrator. It’s a really handy tool that can greatly improve your overall workflow. Here you have learned how to both install Screen on your server and how to use its basic commands.

We hope you found this Linux tutorial helpful. Good luck!

Author
The author

Edward S.

Edward is a content editor with years of experience in IT writing, marketing, and Linux system administration. His goal is to encourage readers to establish an impactful online presence. He also really loves dogs, guitars, and everything related to space.