ESDS Knowledge Base

11
May

Using The Screen Command For Linux

Before starting, I’ll tell you what we can do by using the screen command.

As a Linux sysadmin, it is very common that you have the need to run several commands at once. You will probably open several ssh sessions for this, however, there is a way better, safer and recommended.

Another need that will arise frequently, is to run a command or script that will take hours to complete, such as an rsync. This requires that you keep the connection open on ssh, because if you close, the script or command also will close, which can be a problem if you have your Internet connection interrupted.

Given these problems, we can begin to introduce you to the command screen.

Screen – makes it possible to run several pseudo terminals, manipulate and save your entries and exits on the screen, and copy and paste between windows.

I’ll show you how to run a command that takes hours, within one screen.

We will first install screen, using yum, apt-get, or use a package manager that you have available. In our example we will use yum.

yum install screen

Now type:

Screen

This command will start a new window within the screen for you. You also have the option to launch the command window giving a name (parameter-S). Example:

screen-S gracious 1

In this case, the window will be called “gracious 1.

The screen works like any other within the ssh session. You can now enter any command that will run normally.

If you want to exit the screen session, leaving it active, and maintain the command that was running, do:

Ctrl-a d (control + the press release, and then press d)

So when you want to re-screen window, type:

screen-r

Other options you have when you are inside the screen are:

1. To create a new session:

Ctrl-a c

2. To change between sessions:

Ctrl-a n

There are other possibilities of use. For more information and help, you can use in your terminal:

man screen

Leave a Reply