{"id":99473,"date":"2020-10-28T16:00:00","date_gmt":"2020-10-28T13:00:00","guid":{"rendered":"https:\/\/en.buradabiliyorum.com\/how-to-use-the-gnu-screen-utility-in-linux-cloudsavvy-it\/"},"modified":"2020-10-28T16:00:00","modified_gmt":"2020-10-28T13:00:00","slug":"how-to-use-the-gnu-screen-utility-in-linux-cloudsavvy-it","status":"publish","type":"post","link":"https:\/\/buradabiliyorum.com\/en\/how-to-use-the-gnu-screen-utility-in-linux-cloudsavvy-it\/","title":{"rendered":"#How to Use the GNU Screen Utility in Linux \u2013 CloudSavvy IT"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_85 counter-hierarchy ez-toc-counter ez-toc-custom ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-6a396ef139f84\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #dd3333;color:#dd3333\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #dd3333;color:#dd3333\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-6a396ef139f84\" checked aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/buradabiliyorum.com\/en\/how-to-use-the-gnu-screen-utility-in-linux-cloudsavvy-it\/#Using_The_GNU_Screen_Utility\" >Using The GNU Screen Utility<\/a><\/li><\/ul><\/nav><\/div>\n<p><strong>&#8220;#How to Use the GNU Screen Utility in Linux \u2013 CloudSavvy IT&#8221;<\/strong><\/p>\n<div id=\"article-content-area\">\n<img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-7581\" src=\"https:\/\/www.cloudsavvyit.com\/thumbcache\/0\/0\/49af6f51c78e665d9f50d292b2cd0f32\/p\/uploads\/2020\/10\/06b92500.png\" alt=\"How to use the GNU Screen utility in Linux\" width=\"1200\" height=\"494\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>Do you want to run multiple virtual screen sessions from a single terminal console? Or avoid Internet connection drops from terminating your console session via SSH? If so, welcome the\u00a0<strong>GNU Screen<\/strong> terminal multiplexer into your toolset today!<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Using_The_GNU_Screen_Utility\"><\/span>Using The GNU Screen Utility<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>The <strong>GNU Screen utility<\/strong> for Linux is a versatile screen multiplexer which allows you to start multiple virtual screen sessions (think about them like additional console windows) from within your current terminal session!<\/p>\n<p>Getting started is easy. You can install the GNU Screen tool using <code>sudo apt install screen<\/code> at your terminal command line:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-7582\" src=\"https:\/\/www.cloudsavvyit.com\/thumbcache\/0\/0\/d642eeb7fdac8e1c34bc0d3202b083e1\/p\/uploads\/2020\/10\/ba347446.png\" alt=\"Installing GNU Screen\" width=\"855\" height=\"425\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>If you are using a RedHat\/RPM based operating system, please substitute `apt` to `yum` in the command above.<\/p>\n<p>To open a new virtual console, you can now simply type <code>screen<\/code> and hit enter, which will present you with a splash screen:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-7583\" src=\"https:\/\/www.cloudsavvyit.com\/thumbcache\/0\/0\/2198776cb7830f7d0fbf2077c0e3adf9\/p\/uploads\/2020\/10\/def1eea5.png\" alt=\"GNU Screen Splash Screen\" width=\"674\" height=\"716\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>Simply press space or return to close the splash screen. The command prompt will seem to return, but in fact you are now within a virtual screen session. Think about it like an alternative terminal session, running inside the former terminal session.<\/p>\n<p>One of the great things about GNU screen is that even if the main\/parent terminal session where to somehow fail or crash (for example due to a lost network connection), and even when you close or terminate the main\/parent terminal session, this screen session will remain live and running!<\/p>\n<p>It is easy to check if we are currently inside a screen session or not:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-7585\" src=\"https:\/\/www.cloudsavvyit.com\/thumbcache\/0\/0\/52c44d0954634a15a5d5b099a876b89c\/p\/uploads\/2020\/10\/c3c0de58.png\" alt=\"Checking if this is a GNU Screen session or not\" width=\"598\" height=\"147\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>This if statement tests if the <code>$STY<\/code> variable is set or not. If the <code>$STY<\/code> environment variable is set, then this is a screen session.<\/p>\n<p>So how do we go back to our main\/parent terminal session? This can be done by using a keyboard combination which GNU screen will be listening for in the background. Simply press CTRL+A &gt; CTRL+D. It does not matter if you release or not release the CTRL key while doing so.<\/p>\n<p>You will see something similar to this output:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-7586\" src=\"https:\/\/www.cloudsavvyit.com\/thumbcache\/0\/0\/440abe88b0be1dc0072c9f0331f3715b\/p\/uploads\/2020\/10\/1c9a7549.png\" alt=\"Exiting from a GNU Screen session\" width=\"324\" height=\"36\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>This also tells us we have only detached from the virtual GNU screen session \u2013 it has not terminated, and if we want we can connect back to it. Even if for some reason the main\/parent session had closed, the virtual screen session would not have terminated and we can again connect back to it.<\/p>\n<p>To reconnect to the session, we can issue a simple command:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-7587\" src=\"https:\/\/www.cloudsavvyit.com\/thumbcache\/0\/0\/1f4e25783717b8c48a30da94a01b9ac4\/p\/uploads\/2020\/10\/2882bfb8.png\" alt=\"Reconnecting to a GNU Screen session\" width=\"240\" height=\"21\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>Confirming this command will simply return us to the virtual screen session we had running. Notice that we used the relevant process ID (as reported when we detached from the screen session) to reconnect with the virtual screen session. This also im<a href=\"https:\/\/buradabiliyorum.com\/en\/category\/social-mediaa\/\" data-internallinksmanager029f6b8e52c=\"1\" title=\"Social Media\" target=\"_blank\" rel=\"noopener\">media<\/a>tely clarifies how we can start an indefinite amount of screen sessions (though each one will consume some amount of resources) and connect to whichever one we like by using the <code>screen -d -r<\/code> command.<\/p>\n<p>We can read more about the options we used for this command in the screen inline manual:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-7588\" src=\"https:\/\/www.cloudsavvyit.com\/thumbcache\/0\/0\/348bfffde6b8ee8f96eeb7c2aef01dcf\/p\/uploads\/2020\/10\/dd63ba3b.png\" alt=\"Screen manual clarifying options r and d\" width=\"651\" height=\"73\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>For a wider overview of screen and it\u2019s many functionalities, you can use the <code>man screen<\/code> command:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-7589\" src=\"https:\/\/www.cloudsavvyit.com\/thumbcache\/0\/0\/5ce1cfd12dbf90350986548fcab50abc\/p\/uploads\/2020\/10\/e2bdc0e5.png\" alt=\"GNU Screen Linux manual\" width=\"677\" height=\"359\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>If we want to see a list of screen sessions which are running on the machine at this moment, we can issue a <code>screen -list<\/code> command:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-7590\" src=\"https:\/\/www.cloudsavvyit.com\/thumbcache\/0\/0\/798fc30d8542c6e36d29ce9c20fdce85\/p\/uploads\/2020\/10\/7b581815.png\" alt=\"GNU Screen list\" width=\"607\" height=\"88\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>Note how the session reports as \u2018Detached\u2019 or \u2018Attached\u2019 depending on whether you are still connected with it somewhere or not.<\/p>\n<p>Sometimes you may like to scroll back inside a screen session, for example when more lines of output were generated then the amount of lines which is available in your terminal window size. One would expect this to be as easy as using the mouse to scroll up and down, but is not.<\/p>\n<p>Instead, you can use a CTRL+ESC keyboard combination to enable copy mode (though no actual copy is taken if you only do scrolling), and now your mouse, as well as the standard up\/down cursor keys will work correctly. When you\u2019re done with looking (and\/or copying if you like, for example with your mouse selecting and copying as normal), simply press the ESC key again to abort the copy mode.<\/p>\n<p>At times a program running inside a screen may crash, for example due to a program error or out of memory or disk situation. If this h<a href=\"https:\/\/buradabiliyorum.com\/en\/category\/download-scripts-themes-apps\/\" data-internallinksmanager029f6b8e52c=\"9\" title=\"Download Scripts &amp; Themes &amp; Apps\" target=\"_blank\" rel=\"noopener\">app<\/a>ens, the screen will show as \u2018Dead\u2019 in the <code>screen -list<\/code> output:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-7591\" src=\"https:\/\/www.cloudsavvyit.com\/thumbcache\/0\/0\/318c5233ef5dd65e468b3f02eefff429\/p\/uploads\/2020\/10\/4f9607ed.png\" alt=\"A failed GNU Screen session\" width=\"615\" height=\"131\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>At such point, we can wipe away the dead screen session by issuing a <code>screen -wipe<\/code> command:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-7592\" src=\"https:\/\/www.cloudsavvyit.com\/thumbcache\/0\/0\/4a201b86eb0c965204e68e2980335a69\/p\/uploads\/2020\/10\/e6269b8b.png\" alt=\"A wiped GNU Screen session\" width=\"620\" height=\"190\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>In this article, we explored how to install the GNU screen utility, how to start a new virtual screen session using the same, and how to detach from and reattach to an existing screen session. Finally we look at how to scroll inside screen sessions, as well as looking at how to handle dead screen sessions. <strong>Enjoy!<\/strong>\n<\/div>\n<blockquote>\n<p style=\"text-align: center;\">For forums sites go to <span style=\"color: #ff9900;\"><a style=\"color: #ff9900;\" href=\"https:\/\/forum.buradabiliyorum.com\/\" target=\"_blank\" rel=\"noopener noreferrer\">Forum.BuradaBiliyorum.Com<\/a><\/span><\/strong><\/p>\n<\/blockquote>\n<blockquote>\n<p style=\"text-align: center;\"><strong>If you want to read more like this article, you can visit our <span style=\"color: #ff9900;\"><a style=\"color: #ff9900;\" href=\"https:\/\/en.buradabiliyorum.com\/technology\/\" target=\"_blank\" rel=\"noopener noreferrer\">Technology category.<\/a><\/span><\/strong><\/p>\n<\/blockquote>\n<p><span style=\"color: black;\"><a style=\"color: #ff9900;\" href=\"https:\/\/www.cloudsavvyit.com\/7580\/how-to-use-the-gnu-screen-utility-in-linux\/\" target=\"_blank\" rel=\"noopener noreferrer\">Source<\/a><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#8220;#How to Use the GNU Screen Utility in Linux \u2013 CloudSavvy IT&#8221; Do you want to run multiple virtual screen sessions from a single terminal console? Or avoid Internet connection drops from terminating your console session via SSH? If so, welcome the\u00a0GNU Screen terminal multiplexer into your toolset today! Using The GNU Screen Utility The&#8230;<\/p>\n","protected":false},"author":1,"featured_media":99474,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"fifu_image_url":"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2020\/10\/06b92500.png","fifu_image_alt":"","footnotes":""},"categories":[18],"tags":[],"class_list":["post-99473","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-technology"],"_links":{"self":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts\/99473","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/comments?post=99473"}],"version-history":[{"count":0,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts\/99473\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/media\/99474"}],"wp:attachment":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/media?parent=99473"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/categories?post=99473"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/tags?post=99473"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}