Skip to content

Do you know the screen command?

The screen command is a powerful window manager that multiplexes a physical terminal between several processes. It allows the user to open several instances of different terminals on the same physical terminal. You can even share your terminal with other users.

If you needed to open several SSH connections with your Linux to have more than one terminal available, it’s because you don’t know the screen yet.

Once you type screen, it will open a terminal like any other. But it will enable several commands. To see the HELP screen, type Ctrl-A and “?” (without quotes). All screen commands must be preceded by Ctrl-A.

Imagine that you are connected via SSH to a server and you are going to download a large file that will take 2 hours. You can run the download “inside” the screen, disconnect from the terminal, and then reconnect later, even from another computer.

$screen

$wget http://servidornaweb.com.br/arquivomuitogrande.tar.gz

You can type Crtl-A and the “d” key to disconnect from the terminal. Now you can even log out of the SSH session.

When you want to reconnect to the screen terminal, reconnect to the SSH session, and then type the command:

$screen —r

If you have more than one session open on the screen, you must enter the session you want to connect to. To see which sessions are open:

$ screen -ls

There is a screen on:

12604.pts-0.svnserver (Attached)

1 Socket in /var/run/screen/s-ec2-user.

To connect to session 12604:

$screen —r 12604

You can also open multiple sessions with Ctrl-A, then “c”. To switch between sessions, you must type Ctrl-A and then “n” or “p” to navigate forward (Next) or backward (Previous). This prevents you from having to connect multiple times via SSH.

You can also enable the log of everything that was entered in the terminal by activating the log using the Ctrl-A and “H” command. To turn off logging, just press Ctrl-A and “H” again.

Learn much more about Linux in our online course. You can enroll here with a free 7-day trial. If you already have an account, you can log in here.

Did you like it? Share :-)