How to Use Linux Screen Command With Examples

How to Use Linux Screen Command With Examples
How to Use Linux Screen Command With Examples

Use Linux Screen Command With Examples

The screen command in Linux is used creating terminal multiplexing. By using screen you can run any number of the terminal based applications. Screen command can enable you to resume your work where last time you exited the application. User can open multiple instances of terminal inside one single terminal by using screen command very easily. If you exit the terminal then the process running in the terminal will not break it will be continued in the background so you can resume the session where you left. In this tutorial, you are going to learn How to Use Linux Screen Command With Examples.

Installing Linux Screen

First, confirm the whether screen command is installed or not on your system run following command:

screen --version

You can install Linux screen using the following command in different Linux distros.

To install screen command in Ubuntu, Debian or any Debian based ditro run following command:

sudo apt install screen

To install screen command in CentOS, RHEL run following command:

sudo yum install screen

For Fedora you can type the following command:
sudo dnf install screen

Using Linux Screen

You can start a new screen session by typing following command in terminal:

screen

The output should look like the following:

How to Use Linux Screen Command With Examples - screen
How to Use Linux Screen Command With Examples – screen

Now to get the list of available commands by typing Ctrl+a ? in the current terminal.

Create New Session With Name

You create a new session with specific name by using screen command with -S option:

screen -S NAME_OF_THE_SESSION/pre>

You can replace NAME_OF_THE_SESSION with the name you want to give to a new session.

Detach From Screen Session

You have created a new session you can also detach from the session. To detach from the session enter following keys:

Ctrl+a d

The output should look like:

How to Use Linux Screen Command With Examples - Detach session
How to Use Linux Screen Command With Examples – Detach session

Re-Attach to a Linux Screen Session

You can re-attach to a previous screen session by using -r option with screen command:
To re-attach to a new session run below command:

screen -r

If you have created multiple screen sessions then it will list you all the sessions available, then you should choose one of them and should run the following command:

How to Use Linux Screen Command With Examples - Resume session
How to Use Linux Screen Command With Examples – Resume session
screen -r 7582

After running above command you will be attached to a session with ID 7582.

List All Available Sessions

You can also list all available sessions using -ls option with screen command:

screen -ls

The output should look like:

There are screens on:
        7582.second_session     (Detached)
        7412.new_session        (Detached)
        7105.pts-1.localhost    (Detached)
3 Sockets in /run/screen/S-linux4one.
How to Use Linux Screen Command With Examples - List sessions
How to Use Linux Screen Command With Examples – List sessions

Conclusion

You have successfully learned How to Use Linux Screen Command With Examples. If you have any of the queries regarding this then please dont forget to comment below.

LEAVE A REPLY

Please enter your comment!
Please enter your name here