{"id":3222,"date":"2013-03-12T08:32:25","date_gmt":"2013-03-12T12:32:25","guid":{"rendered":"http:\/\/www.databook.bz\/?page_id=3222"},"modified":"2017-04-03T21:53:02","modified_gmt":"2017-04-04T01:53:02","slug":"lab-project-5-using-screen","status":"publish","type":"page","link":"http:\/\/www.linux-databook.info\/?page_id=3222","title":{"rendered":"Using Screen"},"content":{"rendered":"<p>The screen utility allows launching multiple shells in a single terminal session and provides means to navigate between the running shells.<\/p>\n<p>Remember when you had a remote session running a program and the communications link failed? When that happened the running program was terminated as well and you would have had to restart it from the beginning.<\/p>\n<p>The screen program allows disconnecting the screen session from the terminal session and reconnecting later from the same or a different computer. Another interesting aspect of this feature of using screen to perform CLI tasks on remote hosts is that the screen session will continue to run even if the connectivity to the remote hosts is broken intentionally using the <strong>Ctrl-a d<\/strong> key combination or if the network connection fails. All of the CLI programs running in the screen terminal sessions will continue to run. This means that once communications is reestablished one can log back into the remote host, use the <strong>screen -r<\/strong> command at the login command line to reattach the screen session to the terminal.<\/p>\n<p>So I can start up a bunch of terminal CLI sessions in screen, use <strong>Ctrl-a d<\/strong> to disconnect from screen and logout. Then I can go to another location, login to a host, SSH to the host running screen, login and use the <strong>screen -r<\/strong> command to reconnect to the screen session and all of the programs will still be running.<\/p>\n<p>The screen command can be useful in some environments where physical access to a hardware console is not available to provide access to the Virtual Consoles but the flexibility of multiple shells is needed.<\/p>\n<p>You will find it convenient to use the screen program and in some cases it will be necessary to do so in order to work quickly and efficiently. Unfortunately, the screen command has not been installed as part of most default installations, so you may have to do this.<\/p>\n<p>The network interface should have been started on your computer but if it has not you will have to start it.<\/p>\n<p>You can install the screen package using the following command:<\/p>\n<p align=\"LEFT\"><span style=\"font-family: Liberation Serif,serif;\"><span style=\"color: #000000;\"><span style=\"font-family: Liberation Mono,monospace;\"><span style=\"font-size: small;\"><b>yum -y install screen<\/b><\/span><\/span><\/span><\/span><\/p>\n<p>Remember that this is Linux, not Windows, so it is NOT necessary to reboot after installing most software. One of the very few exceptions would be after installing an updated kernel. The \u201cyum\u201d command, which is used to install remove and update software packages, is covered in more detail in another document.<\/p>\n<p>Now to start screen and learn how it works, follow these steps.<\/p>\n<ol>\n<li>At the CLI type <strong><span style=\"font-family: andale mono,times;\">screen<\/span><\/strong> which will clear the display and leave you at a command prompt.<\/li>\n<li>Type any command such as <strong><span style=\"font-family: andale mono,times;\">ls<\/span><\/strong> to have something displayed in the terminal session besides the command prompt.<\/li>\n<li>Type <span style=\"font-family: andale mono,times;\"><strong>Ctrl-a c<\/strong><\/span> to open a new shell within the screen session.<\/li>\n<li>Enter a different command, such as <strong><span style=\"font-family: andale mono,times;\">df \u2013h<\/span><\/strong> in this new shell.<\/li>\n<li>Type <strong><span style=\"font-family: andale mono,times;\">Ctrl-a<\/span><\/strong> a to switch between screen shells.<\/li>\n<li>Enter <strong><span style=\"font-family: andale mono,times;\">Ctrl-a c<\/span><\/strong> to open a third shell.<\/li>\n<li>Type <strong><span style=\"font-family: andale mono,times;\">Ctrl-a \u201c<\/span><\/strong> to list the open shells. Choose any one except the last one by using the up\/dn arrow keys and hit the <strong>Enter<\/strong> key to switch to that shell.<\/li>\n<li>To close one session, type <strong><span style=\"font-family: andale mono,times;\">exit<\/span><\/strong> and press the <strong>Enter<\/strong> key.<\/li>\n<li>Type the command <strong><span style=\"font-family: andale mono,times;\">Ctrl-a \u201c<\/span><\/strong> to verify that the shell is gone. Notice that the shell with the number you have chosen to close is no longer there and that the other shells have not been renumbered.<\/li>\n<li>To reopen a fresh shell use <strong><span style=\"font-family: andale mono,times;\">Ctrl-a c<\/span><\/strong>.<\/li>\n<li>Type <strong><span style=\"font-family: andale mono,times;\">Ctrl-a \u201c<\/span><\/strong> to verify that the new shell has been created. Notice that it has been opened in the place of the shell that was previously closed.<\/li>\n<li>To disconnect from the screen session, press <strong><span style=\"font-family: andale mono,times;\">Ctrl-a d<\/span><\/strong>. Note that this leaves all of the shells and the programs running in them intact and still running.<\/li>\n<li>Enter the command <strong><span style=\"font-family: andale mono,times;\">screen -list<\/span><\/strong> to list all of the current screen sessions. This can be useful to ensure that you reconnect to the correct screen session if there are multiple ones.<\/li>\n<li>Type <strong><span style=\"font-family: andale mono,times;\">screen \u2013r<\/span><\/strong> to reconnect to the active screen session. If multiple active screen sessions are open, then a list of them will be displayed and you can choose the one to which you wish to connect.<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>The screen utility allows launching multiple shells in a single terminal session and provides means to navigate between the running shells. Remember when you had a remote session running a program and the communications link failed? When that happened the&hellip;<\/p>\n<p class=\"more-link-p\"><a class=\"more-link\" href=\"http:\/\/www.linux-databook.info\/?page_id=3222\">Read more &rarr;<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"parent":2159,"menu_order":3,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-3222","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"http:\/\/www.linux-databook.info\/index.php?rest_route=\/wp\/v2\/pages\/3222","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.linux-databook.info\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"http:\/\/www.linux-databook.info\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"http:\/\/www.linux-databook.info\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.linux-databook.info\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3222"}],"version-history":[{"count":5,"href":"http:\/\/www.linux-databook.info\/index.php?rest_route=\/wp\/v2\/pages\/3222\/revisions"}],"predecessor-version":[{"id":3998,"href":"http:\/\/www.linux-databook.info\/index.php?rest_route=\/wp\/v2\/pages\/3222\/revisions\/3998"}],"up":[{"embeddable":true,"href":"http:\/\/www.linux-databook.info\/index.php?rest_route=\/wp\/v2\/pages\/2159"}],"wp:attachment":[{"href":"http:\/\/www.linux-databook.info\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3222"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}