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 http://apt.sw.be/redhat/el6/en/x86_64/rpmforge/repodata/repomd.xml: [Errno 14] HTTP Error 404 - Not Found Trying other mirror. To address this issue please refer to the below knowledge base article https://access.redhat.com/articles/1320623 If above article doesn't help to resolve this issue please create a bug on https://bugs.centos.org/ 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 http://download.fedoraproject.org/pub/epel/6/x86_64/repodata/7b716df2662d9c59a6804f5545c065b5f75b0015756d56d25b1ee113558c8685-updateinfo.xml.bz2: [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 http://download.fedoraproject.org/pub/epel/6/x86_64/repodata/a3f5e8321f64e4710c977c7f5b7e6e9bba911fb5930f3a8631dfa284d3f980f7-primary.sqlite.bz2: [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 http://apt.sw.be/redhat/el6/en/x86_64/rpmforge/repodata/primary.sqlite.bz2: [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: mirror.wanxp.id * extras: mirror.wanxp.id * rpmforge: ftp.fi.muni.cz * updates: mirror.wanxp.id 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: mirror.wanxp.id * extras: mirror.wanxp.id * rpmforge: ftp.fi.muni.cz * updates: mirror.wanxp.id 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 =========================================================================================================================================================================================================== Installing: 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 Installed: screen.x86_64 0:4.1.0-0.23.20120314git3c2946.el7_2 Complete! [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 [email protected] [email protected]'s password: Last login: Mon Sep 19 11:30:42 2016 from xxx.xxx.xxx.xxx [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 :
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 :
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 * [email protected]:/home/remoteuser/backup-source-code The authenticity of host 'xxx.xxx.xxx.xxx (xxx.xxx.xxx.xxx)' 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 'xxx.xxx.xxx.xxx' (RSA) to the list of known hosts. [email protected]'s password: sending incremental file list xxx/ xxx/xxx/ xxx xxx/xxx xxx/xxx/xxx ... xxx/xxx xxx/xxx/xxx xxx/ sent 37601202448 bytes received 19564898 bytes 13869407.32 bytes/sec total size is 37511603805 speedup is 1.00 [root@hostname html]# pwd /var/www/html [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.]tty.host" 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”