{"id":289,"date":"2023-02-27T11:40:51","date_gmt":"2023-02-27T07:40:51","guid":{"rendered":"https:\/\/kidds.co.za\/?p=289"},"modified":"2023-05-19T09:19:33","modified_gmt":"2023-05-19T05:19:33","slug":"linux-screen","status":"publish","type":"post","link":"https:\/\/kidds.co.za\/index.php\/2023\/02\/27\/linux-screen\/","title":{"rendered":"Linux Screen"},"content":{"rendered":"\n<p><strong>The short version that you need, the rest is nice to know but this is your bread and butter.<\/strong><\/p>\n\n\n\n<p><strong>screen <\/strong>(starts a new session) this is once off until you destroy it or server\/system restart.<\/p>\n\n\n\n<p><strong>CTRL+A<\/strong> (then release both) then press <strong>D<\/strong> will put the session into the back.<\/p>\n\n\n\n<p><strong>screen -r<\/strong> (will reconnect you to that session) <\/p>\n\n\n\n<p>(i recommend you add an alias to your bashrc. <strong>alias sc=&#8217;screen -r&#8217;<\/strong> (then simply type sc on login and you are set. If session is found it will put you right into it)<\/p>\n\n\n\n<p><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>Obviously : first install screen on your server \/ system. Ubuntu &#8211; <em>sudo apt install screen<\/em><\/p>\n\n\n\n<p>Once install on your system, get used to doing the below or above directly after logging in to the system.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>Things to remember CTRL-D will close\/destroy\/terminate the screen session, not put it into the back. You need to get used to not hitting this to leave a system quickly. CTRL+A then D is how to put the screen session into the back. CTRL+A then release and press D. this will become your new i am ending my server session go to.<\/p>\n\n\n\n<p>Type : <strong>screen<\/strong> hit enter and you have a session going.<\/p>\n\n\n\n<p><strong><em>Every time you log in to your system\/server simply type : <\/em>screen -r<\/strong> <\/p>\n\n\n\n<p>And it will auto connect you right back into where you where. Mid script, what ever, no more ip resets taking you back to unwritten files.<\/p>\n\n\n\n<p>This <strong>screen -r<\/strong> will become your best friend very quickly once you put it on top of your logged in command list.<\/p>\n\n\n\n<p>Every now an then type screen -list just to make sure you dont have a bunch of sessions you might have left open. typing screen and hitting enter will create a new session not connect you to one thats already running in the back. It is easy to get multiple session without realizing it.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"starting-linux-screen\">Starting Linux Screen<\/h2>\n\n\n\n<p>To start a screen session, simply type&nbsp;<code>screen<\/code>&nbsp;in your console:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>screen<\/code><\/pre>\n\n\n\n<p>This will open a screen session, create a new window, and start a shell in that window.<\/p>\n\n\n\n<p>Now that you have opened a screen session, you can get a list of commands by typing:<\/p>\n\n\n\n<p><code>Ctrl+a<\/code>\u00a0<code>?<\/code> \/ Press CTRL(hold it)+A release CTRL and A, then press ? this is for all the CTRL+A options.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"starting-named-session\">Starting Named Session<\/h3>\n\n\n\n<p>Named sessions are useful when you run multiple screen sessions. To create a named session, run the screen command with the following arguments:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>screen -S session_name<\/code><\/pre>\n\n\n\n<p>It\u2019s always a good idea to choose a descriptive session name.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"working-with-linux-screen-windows\">Working with Linux Screen Windows<\/h2>\n\n\n\n<p>When you start a new screen session, it creates a single window with a shell in it.<\/p>\n\n\n\n<p>You can have multiple windows inside a Screen session.<\/p>\n\n\n\n<p>To create a new window with shell type&nbsp;<code>Ctrl+a<\/code>&nbsp;<code>c<\/code>, the first available number from the range&nbsp;<code>0...9<\/code>&nbsp;will be assigned to it.<\/p>\n\n\n\n<p>Below are some most common commands for managing Linux Screen Windows:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>Ctrl+a<\/code>&nbsp;<code>c<\/code>&nbsp;Create a new window (with shell).<\/li>\n\n\n\n<li><code>Ctrl+a<\/code>&nbsp;<code>\"<\/code>&nbsp;List all windows.<\/li>\n\n\n\n<li><code>Ctrl+a<\/code>&nbsp;<code>0<\/code>&nbsp;Switch to window 0 (by number).<\/li>\n\n\n\n<li><code>Ctrl+a<\/code>&nbsp;<code>A<\/code>&nbsp;Rename the current window.<\/li>\n\n\n\n<li><code>Ctrl+a<\/code>&nbsp;<code>S<\/code>&nbsp;Split current region horizontally into two regions.<\/li>\n\n\n\n<li><code>Ctrl+a<\/code>&nbsp;<code>|<\/code>&nbsp;Split current region vertically into two regions.<\/li>\n\n\n\n<li><code>Ctrl+a<\/code>&nbsp;<code>tab<\/code>&nbsp;Switch the input focus to the next region.<\/li>\n\n\n\n<li><code>Ctrl+a<\/code>&nbsp;<code>Ctrl+a<\/code>&nbsp;Toggle between the current and previous windows<\/li>\n\n\n\n<li><code>Ctrl+a<\/code>&nbsp;<code>Q<\/code>&nbsp;Close all regions but the current one.<\/li>\n\n\n\n<li><code>Ctrl+a<\/code>&nbsp;<code>X<\/code>&nbsp;Close the current region.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"detach-from-linux-screen-session\">Detach from Linux Screen Session<\/h2>\n\n\n\n<p>You can detach from the screen session at any time by typing:<\/p>\n\n\n\n<p><code>Ctrl+a<\/code>&nbsp;<code>d<\/code>The program running in the screen session will continue to run after you detach from the session.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"reattach-to-a-linux-screen\">Reattach to a Linux Screen<\/h2>\n\n\n\n<p>To resume your screen session use the following command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>screen -r<\/code><\/pre>\n\n\n\n<p>In case you have multiple screen sessions running on your machine, you will need to append the screen session ID after the&nbsp;<code>r<\/code>&nbsp;switch.<\/p>\n\n\n\n<p>To find the session ID list the current running screen sessions with:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>screen -ls<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>There are screens on:\n    10835.pts-0.linuxize-desktop   (Detached)\n    10366.pts-0.linuxize-desktop   (Detached)\n2 Sockets in \/run\/screens\/S-linuxize.\n<\/code><\/pre>\n\n\n\n<p>If you want to restore screen 10835.pts-0, then type the following command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>screen -r 10835<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"customize-linux-screen\">Customize Linux Screen<\/h2>\n\n\n\n<p>When&nbsp;<code>screen<\/code>&nbsp;is started, it reads its configuration parameters from&nbsp;<code>\/etc\/screenrc<\/code>&nbsp;and&nbsp;<code>~\/.screenrc<\/code>&nbsp;if the file is present. We can modify the default Screen settings according to our preferences using the&nbsp;<code>.screenrc<\/code>&nbsp;file.<\/p>\n\n\n\n<p>Here is a sample&nbsp;<code>~\/.screenrc<\/code>&nbsp;configuration with customized status line and few additional options:<\/p>\n\n\n\n<p>~\/.screenrc<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><em># Turn off the welcome message<\/em>\nstartup_message off\n\n<em># Disable visual bell<\/em>\nvbell off\n\n<em># Set scrollback buffer to 10000<\/em>\ndefscrollback 10000\n\n<em># Customize the status line<\/em>\nhardstatus alwayslastline\nhardstatus string '%{= kG}&#91; %{G}%H %{g}]&#91;%= %{= kw}%?%-Lw%?%{r}(%{W}%n*%f%t%?(%u)%?%{r})%{w}%?%+Lw%?%?%= %{g}]&#91;%{B} %m-%d %{W}%c %{g}]'\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"basic-linux-screen-usage\">Basic Linux Screen Usage&nbsp;<a href=\"https:\/\/linuxize.com\/post\/how-to-use-linux-screen\/#basic-linux-screen-usage\">#<\/a><\/h2>\n\n\n\n<p>Below are the most basic steps for getting started with screen:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>On the command prompt, type&nbsp;<code>screen<\/code>.<\/li>\n\n\n\n<li>Run the desired program.<\/li>\n\n\n\n<li>Use the key sequence&nbsp;<code>Ctrl-a<\/code>&nbsp;+&nbsp;<code>Ctrl-d<\/code>&nbsp;to detach from the screen session.<\/li>\n\n\n\n<li>Reattach to the screen session by typing&nbsp;<code>screen -r<\/code>.<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>The short version that you need, the rest is nice to know but this is your bread and butter. screen (starts a new session) this is once off until you destroy it or server\/system restart. CTRL+A (then release both) then press D will put the session into the back. screen -r (will reconnect you to [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7,10,2],"tags":[22],"class_list":["post-289","post","type-post","status-publish","format-standard","hentry","category-general-server-stuff","category-general-system-stuff","category-linux","tag-screen"],"_links":{"self":[{"href":"https:\/\/kidds.co.za\/index.php\/wp-json\/wp\/v2\/posts\/289","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kidds.co.za\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kidds.co.za\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kidds.co.za\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kidds.co.za\/index.php\/wp-json\/wp\/v2\/comments?post=289"}],"version-history":[{"count":4,"href":"https:\/\/kidds.co.za\/index.php\/wp-json\/wp\/v2\/posts\/289\/revisions"}],"predecessor-version":[{"id":336,"href":"https:\/\/kidds.co.za\/index.php\/wp-json\/wp\/v2\/posts\/289\/revisions\/336"}],"wp:attachment":[{"href":"https:\/\/kidds.co.za\/index.php\/wp-json\/wp\/v2\/media?parent=289"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kidds.co.za\/index.php\/wp-json\/wp\/v2\/categories?post=289"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kidds.co.za\/index.php\/wp-json\/wp\/v2\/tags?post=289"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}