{"id":2269,"date":"2018-11-02T02:32:22","date_gmt":"2018-11-02T02:32:22","guid":{"rendered":"https:\/\/www.appservgrid.com\/paw92\/?p=2269"},"modified":"2018-11-02T09:40:34","modified_gmt":"2018-11-02T09:40:34","slug":"how-to-multi-task-in-linux-with-the-command-line","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2018\/11\/02\/how-to-multi-task-in-linux-with-the-command-line\/","title":{"rendered":"How to Multi-Task in Linux with the Command Line"},"content":{"rendered":"<p><a href=\"https:\/\/www.rosehosting.com\/blog\/wp-content\/uploads\/2018\/10\/How-to-Multi-Task-in-Linux-with-the-Command-Line.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.rosehosting.com\/blog\/wp-content\/uploads\/2018\/10\/How-to-Multi-Task-in-Linux-with-the-Command-Line.jpg\" alt=\"How to Multi-Task in Linux with the Command Line\" width=\"742\" height=\"372\" \/><\/a><\/p>\n<p>How to Multi-Task in Linux with the Command Line<\/p>\n<p>One of the most jarring moments when moving from a Windows-based environment to using the command line is the loss of easy multi-tasking. Even on Linux, if you use an X Window system, you can use the mouse to just click on a new program and open it. On the command line, however, you\u2019re pretty much stuck with what\u2019s on your screen at any given time. In this tutorial, we will show you how to multi-task in Linux with the command line.<\/p>\n<h2>Background and Foreground Process Management<\/h2>\n<p>However, there are still ways to multi-task in Linux, and some of them are more comprehensive than others. One in-built way that doesn\u2019t require any kind of additional software is simply moving processes into the background and the foreground. We\u2019d <a href=\"https:\/\/www.rosehosting.com\/blog\/how-to-run-commands-simultaneously-in-linux\/\">written a tutorial<\/a> on that a short while back. However, it has some disadvantages.<\/p>\n<h3>Disadvantages<\/h3>\n<p><b>First<\/b>, to send a process into the background, you have to pause it first. There\u2019s no way to send an already running program into the background and keep it running in one go.<\/p>\n<p><b>Second<\/b>, you need to break your workflow to start a new command. You have to exit what you\u2019re currently doing and type more commands into the shell. It works, but it\u2019s inconvenient.<\/p>\n<p><b>Third<\/b>, you have to look out for output from the background processes. Any output from them will appear on the command line and interfere with what you\u2019re doing in the current moment. So background tasks need to either redirect their output to a separate file, or they need to be muted altogether.<\/p>\n<p>Because of these disadvantages, there are huge problems with background and foreground process management. A better solution is to use the \u201cscreen\u201d command utility as shown below.<\/p>\n<h2>But First \u2013 You Can Always Open a new SSH Session<\/h2>\n<p>Don\u2019t forget that you just open a new SSH session. Here\u2019s a screenshot of we doing just that:<\/p>\n<p><a href=\"https:\/\/www.rosehosting.com\/blog\/wp-content\/uploads\/2018\/10\/Open-Two-Separate-SSH-Shells.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.rosehosting.com\/blog\/wp-content\/uploads\/2018\/10\/Open-Two-Separate-SSH-Shells.jpg\" alt=\"Open Two Separate SSH Shells\" width=\"560\" height=\"299\" \/><\/a><\/p>\n<p>It can get inconvenient to open new sessions all the time. And that\u2019s when you need \u201cscreen\u201d<\/p>\n<h2>Using \u201cScreen\u201d Instead<\/h2>\n<p>The \u201cscreen\u201d utility allows you to have multiple workflows open at the same times \u2013 the closest analog to \u201cwindows\u201d. It\u2019s available by default within the regular Linux repositories. Install it in CentOS\/RHEL like this:<\/p>\n<p>sudo yum install screen<\/p>\n<p><a href=\"https:\/\/www.rosehosting.com\/blog\/wp-content\/uploads\/2018\/10\/Install-Screen.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.rosehosting.com\/blog\/wp-content\/uploads\/2018\/10\/Install-Screen.jpg\" alt=\"install screen linux\" width=\"560\" height=\"431\" \/><\/a><\/p>\n<h2>Opening a New Screen<\/h2>\n<p>Now start your session by typing \u201cscreen\u201d.<\/p>\n<p>This will create a blank window within your existing SSH session and give it a number that\u2019s shown in the title bar like this:<\/p>\n<p><a href=\"https:\/\/www.rosehosting.com\/blog\/wp-content\/uploads\/2018\/10\/Waiting-for-Input.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.rosehosting.com\/blog\/wp-content\/uploads\/2018\/10\/Waiting-for-Input.jpg\" alt=\"Waiting for Input\" width=\"650\" height=\"203\" \/><\/a><\/p>\n<p>My screen here has the number \u201c0\u201d as shown. In this screenshot, I\u2019m using a dummy \u201cread\u201d command to block the terminal and make it wait for input. Now let\u2019s say we want to do something else while we wait.<\/p>\n<p>To open a new screen and do something else, we type:<\/p>\n<p>ctrl+a c<\/p>\n<p>\u201cctrl+a\u201d is the default key combination for managing screens within the screen program. What you type after it, determines the action. So for example:<\/p>\n<ul>\n<li>ctrl+a c \u2013 <b>C<\/b>reates a new screen<\/li>\n<li>ctrl+a <i>[number]<\/i> \u2013 Goes to a specific screen number<\/li>\n<li>ctrl+a k \u2013 <b>K<\/b>ills the current screen<\/li>\n<li>ctrl+a n \u2013 Goes to the <b>n<\/b>ext screen<\/li>\n<li>ctrl+a \u201d \u2013 Lists all active screens in the session<\/li>\n<\/ul>\n<p>So if we press \u201cctrl+a c\u201d, we get a new screen with a new number as shown here:<\/p>\n<p><a href=\"https:\/\/www.rosehosting.com\/blog\/wp-content\/uploads\/2018\/10\/Second-Screen-Linux.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.rosehosting.com\/blog\/wp-content\/uploads\/2018\/10\/Second-Screen-Linux.jpg\" alt=\"Second Screen Linux\" width=\"650\" height=\"189\" \/><\/a><\/p>\n<p>You can use the cursor keys to navigate the list and go to whichever screen you want.<br \/>\nScreens are the closest thing you\u2019ll get to a \u201cwindows\u201d like system in the Linux command line. Sure, it\u2019s not as easy as clicking with the mouse, but then the graphical subsystem is very resource intensive in the first place. With screens, you can get almost the same functionality and enable full multi-tasking!<\/p>\n<p>If you are one of our managed VPS hosting customers, you can always ask our system administrators to set up this for you, They are available 24\/7 and can take care of your request immediately.<\/p>\n<p>If you liked this post on how to multi-task in Linux command line, please share it with your friends on social media networks, or if you have any question regarding the blog post please leave a comment below and one of our system administrators will reply to it.<\/p>\n<p><a href=\"http:\/\/lxer.com\/module\/newswire\/ext_link.php?rid=262227\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>How to Multi-Task in Linux with the Command Line One of the most jarring moments when moving from a Windows-based environment to using the command line is the loss of easy multi-tasking. Even on Linux, if you use an X Window system, you can use the mouse to just click on a new program and &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2018\/11\/02\/how-to-multi-task-in-linux-with-the-command-line\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;How to Multi-Task in Linux with the Command Line&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-2269","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/2269","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=2269"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/2269\/revisions"}],"predecessor-version":[{"id":2311,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/2269\/revisions\/2311"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=2269"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=2269"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=2269"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}