Using Screen in Linux via Command Line

Posted on

In this article, screen utility command will be presented as tool used to have a multiple screen within one SSH remote server’s connection. What is the simple language for the above statement ?. Well, simply by using screen utility you can just connect once to host, server workstation remotely using SSH remote connection and can done so many simultaneous tasks at a time.

First of all, to use ‘screen’, make sure it exists and if it is not, it needs to be search whether the package can be retrieved from the current repository :

yum search screen

The output of the command’s execution :

[root@hostname ~]# yum search screen
Loaded plugins: fastestmirror
base                                                                                                                                                                                | 3.6 kB  00:00:00
epel                                                                                                                                                                                | 4.3 kB  00:00:00
extras                                                                                                                                                                              | 3.4 kB  00:00:00
pgdg93                                                                                                                                                                              | 4.1 kB  00:00:00
pgdg94                                                                                                                                                                              | 4.1 kB  00:00:00 [Errno 14] HTTP Error 404 - Not Found
Trying other mirror.
To address this issue please refer to the below knowledge base article

If above article doesn't help to resolve this issue please create a bug on

rpmforge                                                                                                                                                                            | 1.9 kB  00:00:00
updates                                                                                                                                                                             | 3.4 kB  00:00:00
upgrade                                                                                                                                                                             | 1.9 kB  00:00:00
(1/11): base/7/x86_64/group_gz                                                                                                                                                      | 155 kB  00:00:00
(2/11): base/7/x86_64/primary_db                                                                                                                                                    | 5.3 MB  00:00:00
(3/11): epel/x86_64/group_gz                                                                                                                                                        | 150 kB  00:00:04
(4/11): extras/7/x86_64/primary_db                                                                                                                                                  | 165 kB  00:00:00
epel/x86_64/updateinfo         FAILED [Errno 14] HTTP Error 404 - Not Found.4 MB  00:00:24 ETA
Trying other mirror.
(5/11): pgdg94/7/x86_64/group_gz                                                                                                                                                    |  331 B  00:00:02
(6/11): pgdg93/7/x86_64/group_gz                                                                                                                                                    |  332 B  00:00:02
(7/11): pgdg94/7/x86_64/primary_db                                                                                                                                                  | 146 kB  00:00:03
(8/11): updates/7/x86_64/primary_db                                                                                                                                                 | 7.8 MB  00:00:01
(9/11): pgdg93/7/x86_64/primary_db                                                                                                                                                  | 115 kB  00:00:04
epel/x86_64/primary_db         FAILED [Errno 14] HTTP Error 404 - Not Found14 MB  00:00:03 ETA
Trying other mirror.
(1/2): upgrade/primary_db                                                                                                                                                           |  14 kB  00:00:00
rpmforge/primary_db            FAILED [Errno 14] HTTP Error 404 - Not Found                                                        ]  0.0 B/s |    0 B  --:--:-- ETA
Trying other mirror.
(2/2): rpmforge/primary_db                                                                                                                                                          | 2.7 MB  00:00:23
Determining fastest mirrors
* base:
* extras:
* rpmforge:
* updates:
epel/x86_64/primary_db                                                                                                                                                              | 5.9 MB  00:00:05
=========================================================================================== N/S matched: screen ===========================================================================================
gnome-screensaver-frogs.noarch : GNOME Screensaver Slideshow of Frogs
gnome-screenshot.x86_64 : A screenshot utility for GNOME
gnome-shell-extension-screenshot-window-sizer.noarch : Screenshot window sizer for GNOME Shell
kdeartwork-screensavers.x86_64 : screensavers for KDE
libkscreen-devel.i686 : Development files for libkscreen
libkscreen-devel.x86_64 : Development files for libkscreen
perl-CGI-Screen.noarch : Extension for easy creation of multi screen CGI scripts
perl-Term-Screen.x86_64 : Term::Cap based screen positioning module
screen.x86_64 : A screen manager that supports multiple logins on one terminal
screenie.noarch : Small frontend for screen
silkscreen-expanded-fonts.noarch : Expanded Silkscreen font family
silkscreen-fonts.noarch : Silkscreen four member type family
silkscreen-fonts-common.noarch : Common files for Silkscreen fonts (documentation...)
xscreensaver.x86_64 : X screen saver and locker
xscreensaver-base.x86_64 : A minimal installation of xscreensaver
xscreensaver-extras.x86_64 : An enhanced set of screensavers
xscreensaver-extras-gss.x86_64 : Desktop files of extras for gnome-screensaver
xscreensaver-gl-base.x86_64 : A base package for screensavers that require OpenGL
xscreensaver-gl-extras.x86_64 : An enhanced set of screensavers that require OpenGL
xscreensaver-gl-extras-gss.x86_64 : Desktop files of gl-extras for gnome-screensaver
xstar-xscreensaver.x86_64 : XScreenSaver support for xstar
byobu.noarch : Light-weight, configurable window manager built upon GNU screen
caribou.i686 : A simplified in-place on-screen keyboard
caribou.x86_64 : A simplified in-place on-screen keyboard
fbdump.x86_64 : Take screenshots using the framebuffer device
florence.x86_64 : Extensible scalable on-screen virtual keyboard for GNOME
fros.noarch : Universal screencasting frontend with pluggable support for various backends
fros-gnome.noarch : fros plugin for screencasting using Gnome3 integrated screencaster
fros-recordmydesktop.noarch : fros plugin for screencasting using recordmydesktop as a backend
gnome-shell-extension-window-list.noarch : Display a window list at the bottom of the screen in GNOME Shell
gruler.x86_64 : Customizable screen ruler
iok.x86_64 : Indic Onscreen Virtual Keyboard
kacst-screen-fonts.noarch : Fonts for arabic from arabeyes project
kmag.x86_64 : A screen magnifier
kruler.x86_64 : A screen ruler and color measurement tool
kscreen.x86_64 : KDE Display Management software
ksnapshot.x86_64 : A screen capture utility
libkscreen.i686 : Display configuration library
libkscreen.x86_64 : Display configuration library
mesa-libOSMesa.i686 : Mesa offscreen rendering libraries
mesa-libOSMesa.x86_64 : Mesa offscreen rendering libraries
mesa-libOSMesa-devel.i686 : Mesa offscreen rendering development package
mesa-libOSMesa-devel.x86_64 : Mesa offscreen rendering development package
pbstop.x86_64 : Full-screen curses monitor for PBS
perl-Catalyst-Plugin-StackTrace.noarch : Display a stack trace on the debug screen
perl-Curses.x86_64 : Perl module for terminal screen handling and optimization
php-pecl-ncurses.x86_64 : Terminal screen handling and optimization package
python-BeautifulSoup.noarch : HTML/XML parser for quick-turnaround applications like screen-scraping
python-beautifulsoup.noarch : Python library for screen-scraping HTML
python-beautifulsoup4.noarch : HTML/XML parser for quick-turnaround applications like screen-scraping
pyvnc2swf.noarch : VNC screen recorder
redshift.x86_64 : Adjusts the color temperature of your screen according to time of day
svgalib.x86_64 : Low-level fullscreen SVGA graphics library
svgalib.i686 : Low-level fullscreen SVGA graphics library
topless.noarch : display command output on the whole screen like ``top''
touchcal.x86_64 : Calibration utility for touch screens
tslib.x86_64 : Abstraction layer for touchscreen panel event
tslib.i686 : Touchscreen Access Library
xinput_calibrator.x86_64 : A generic touchscreen calibration program for X.Org
xlockmore.x86_64 : Screen lock and screen saver
xonclock.x86_64 : On-screen analog clock
xosd.i686 : On-screen display library for X
xosd.x86_64 : On-screen display library for X
xosd-devel.i686 : Development files for the XOSD on-screen display library
xosd-devel.x86_64 : Development files for the XOSD on-screen display library

Name and summary matches only, use "search all" for everything.
[root@hostname ~]#

Found it !, It is shown above in the following line :

screen.x86_64 : A screen manager that supports multiple logins on one terminal

The command used to install using ‘yum’ is shown as follows :

yum install screen

The output of the above command’s execution in real is shown below :

[root@application ~]# yum install screen
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base:
* extras:
* rpmforge:
* updates:
Resolving Dependencies
--> Running transaction check
---> Package screen.x86_64 0:4.1.0-0.23.20120314git3c2946.el7_2 will be installed
--> Finished Dependency Resolution
Dependencies Resolved

Package                                  Arch                                     Version                                                                 Repository                                 Size
screen                                   x86_64                                   4.1.0-0.23.20120314git3c2946.el7_2                                      updates                                   552 k

Transaction Summary
Install  1 Package

Total download size: 552 k
Installed size: 914 k
Is this ok [y/d/N]: y
Downloading packages:
screen-4.1.0-0.23.20120314git3c2946.el7_2.x86_64.rpm                                                                                                                                | 552 kB  00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : screen-4.1.0-0.23.20120314git3c2946.el7_2.x86_64                                                                                                                                        1/1
Verifying  : screen-4.1.0-0.23.20120314git3c2946.el7_2.x86_64                                                                                                                                        1/1emoteuser

screen.x86_64 0:4.1.0-0.23.20120314git3c2946.el7_2

[root@hostname ~]#

After successfully installing screen utility, it can be directly used and executed in command line as follows :

1.  Try to login first whether it is logging in to local computer or trying to open remote connection as follows :

user@hostname:~$ ssh's password:
Last login: Mon Sep 19 11:30:42 2016 from
[remoteuser@remotehostname ~]$ sudo su -
[sudo] password for remoteuser:
[root@remotehostname ~]# cd /home/.sites/

2. After successfully connected to the remote host, server or workstation, directly try to create a new screen. To be able to create a new screen which contain a new session which can be assigned certain task, first of all, create the new screen. Below is the command executed to create a new screen :

[root@hostname html]# screen -R screen_name

Description :
screen : It is a command which is used to call screen utility which is basically a terminal emulation. 
-R : It is a command line option for screen utility which is used to reattach session specified in the parameter given  
screen_name : It is a parameter given for the session which is going to be reattach or to be created.

For an example :

screen -R test

The above command execution can be shown in the image below :

Using Screen in Linux via Command Line
Using Screen in Linux via Command Line

The above command is used to create a new session of terminal named test. Executing the above command will open a new screen in the same terminal or in the same remote connection which the user will be presented the same bash prompt display. Below is the screen display when the a new session is being created by using ‘screen’ command :

Using Screen in Linux via Command Line
Using Screen in Linux via Command Line

There is a notification in the bottom left side of the terminal used to execute the ‘screen’ command.  It is read as “New Screen…” where it is actually notify user that the new screen is being created as the result of ‘screen’ command being executed. Wait for a few seconds after the command to create screen is being executed, the notification read as “New Screen…” will appear at the bottom left side of the terminal. It  depends on the terminal and also Linux distribution used to execute the command whether the notification will be displayed or not.

3. After that, the new screen contains bash prompt ready to be used for a new task will appear :

[root@hostname html]#

Check the content of the directory by typing the command ‘ls -al’ as follows :

[root@hostname html]# ls -al
total 20
drwxr-xr-x.  5 root root 4096 Apr 28 23:22 .
drwxr-xr-x. 10 root root 4096 Sep 19 11:32 ..
drwxr-xr-x.  6 root root 4096 Jul 14  2014 backup
drwxr-xr-x   3 root root 4096 Jan  9  2014 temp
drwxr-xr-x.  6 root root 4096 Jul 15  2014 source-code
[root@hostname html]#

Execute the task which is going to be run in the background so that it can be left behind to start another task. For an example in this context is to copy some files and the copy process in the screen is shown below :

[root@remotehostname html]# rsync -av *
The authenticity of host ' (' can't be established.
RSA key fingerprint is xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '' (RSA) to the list of known hosts.'s password:
sending incremental file list
sent 37601202448 bytes  received 19564898 bytes  13869407.32 bytes/sec
total size is 37511603805  speedup is 1.00
[root@hostname html]# pwd
[root@hostname html]#
[root@hostname www]# du -sh html/
39G     html/
[root@hostname html]#

4. To return to the original screen and doing another task is actually can be done by typing Ctrl+A and D. And in the original screen, there is a command which can be executed to display another active screen available by typing the command below :

screen -r

By typing the command, the display in the screen will shown the following output :

[root@hostname html]# screen -r
There are several suitable screens on:
19658.test      (Detached)
21846.dump      (Attached)
14463.copy      (Detached)
Type "screen [-d] -r [pid.]" to resume one of them.
[root@hostname html]# 

Just type the id of the screen after ‘screen -r’ command if that screen is going to be accessed and to see whether the process or task in that screen has already finished or not. It is just like the command shown below :

[root@hostname html]# screen -rd 19658.test

Since the process has already finished based on the previous output,  return back to the main session terminal and type Ctrl+A, D

One thought on “Using Screen in Linux via Command Line

Leave a Reply