How to Install and Use Screen in Linux?

What is Screen in Linux?

In Linux, a screen is a utility that allows you to create multiple terminal sessions within a single terminal window. It's like having multiple virtual terminal windows running within a single physical terminal window.

Running long-running processes: The screen allows you to start a process in a terminal session and keep it running even when you close the terminal window or lose the connection to the server.

Running multiple terminal sessions: With Screen, you can have multiple terminal sessions running in a single window, which can be helpful for multitasking or managing several tasks at once.

How to Install Screen?

Kindly follow the below steps to install Screen.

Step 1. Connect your server via SSH.

Step 2. Enter the following command to update the package list.

# yum update (CentOS)
# apt-get update (Ubuntu)

Step 3. Enter the following command to install the screen.

# sudo yum install screen (CentOS)

# sudo apt install screen (Ubuntu)


How to Use Screen in Linux?

Step 1. To start a new Screen session, enter the command screen.

# screen

Step 2. To detach from the Screen session and return to the main terminal window, press Ctrl-a followed by d. This will detach the session and leave it running in the background.

Step 3. To reattach to the Screen session later, you can use the following command:

# screen -r

This will reattach to the last Screen session you detached from. If you have multiple Screen sessions running, you can specify which one to attach to using the session ID, which is displayed in the list of running sessions when you run the screen -ls command.

# screen -r <session_id>


Creating and Managing Multiple Screen Sessions:

Step 1. You can create multiple Screen sessions by running the screen command followed by a session name:

Syntex: screen -S <session_name>

# screen -S install

This will create a new Screen session with the specified name.

Step 2. You can switch between different sessions by running the following command:

Syntex: screen -r <session_name>

# screen -r install

Step 3. To terminate a screen session, simply detach from it and then run the following command:

# screen -X -S session_name quit

This will terminate the screen session with the name session_name.

That's all. You can follow our article to install and use the screen.


Was this answer helpful?

« Back