Press "Enter" to skip to content

How to Use Screen on Ubuntu 16.04

saumyakswain 0

GNU Screen is a full-screen window manager that multiplexes a physical terminal between several processes, typically interactive shells.

A remote connection can be interrupted due to many reasons including network outrage. In such a scenario, there is a high probability of losing SSH access in the middle of a task. This may terminate the session and the ongoing job while the system in an unpredictable state. The GNU screen can come to rescue in such a situation.

Installation

It comes pre-installed on Ubuntu Server 16.04. If for any reason, it has been removed, you can install it by the following command.

 
sudo apt update
sudo apt install screen 

Usage

To use screen just type “screen” in a shell/terminal and hit “enter”.

 screen 

It will display a long message. Just hit “enter”. You are in a screen terminal now. To verify type “Ctrl+a” followed by “v”. You should see an output similar like “screen 4.03.01 (GNU) 28-Jun-15”.

 Ctrl-a v 
 screen 4.03.01 (GNU) 28-Jun-15 

Open a new window within the screen by typing “Ctrl+a” followed by “c”.

 Ctrl-a c 

You have opened a new window within the screen. Now run “top” in this window.

 top 

To go back to the previous window press “Ctrl+a” followed by “p”.

 Ctrl-a p 

Similarly to go to the next window press “n” instead of “p”.

 Ctrl-a n 

You can open a few more windows by pressing “Ctrl+a” followed by “c”.

 
Ctrl-a c
Ctrl-a c

To keep track of all the windows type:

 Ctrl-a w 

This will output a numbered list of windows starting from 0 with the current window marked by a star. You can switch to a particular window by pressing “Ctrl+a” followed by the screen number. To switch to the first window type:

 Ctrl-a 0 

Close the shell. Now open a new shell and connect to your server and type “screen -r”.

 screen -r 

You should be taken back to where you left off.

If, instead, you see a message similar to the following then the screen has not detached.

 
There is a screen on:
 1710.pts-0.ip-172-31-28-182 (02/04/18 16:59:55) (Attached)
There is no screen to be resumed.

You can reattach the screen by the following command.

 screen -x 

To detach a screen any time and get back to the terminal which started the screen, type the following.

 Ctrl-a d 
 [detached from 1604.pts-0.ip-172-31-28-182] 

The current screen will be detached and sent to the background. Now attach/resume the screen by typing “screen -r”.

 screen -r 

 

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: