{"id":6653,"date":"2021-06-02T17:21:59","date_gmt":"2021-06-02T17:21:59","guid":{"rendered":"https:\/\/linuxways.net\/?p=6653"},"modified":"2021-06-02T17:21:59","modified_gmt":"2021-06-02T17:21:59","slug":"how-to-use-screen-command-to-manage-terminal-sessions-in-ubuntu-20-04","status":"publish","type":"post","link":"https:\/\/linuxways.net\/de\/ubuntu\/how-to-use-screen-command-to-manage-terminal-sessions-in-ubuntu-20-04\/","title":{"rendered":"How to Use Screen Command to Manage Terminal Sessions in Ubuntu 20.04"},"content":{"rendered":"<p>Sometimes we need to use multiple terminal sessions within one window while performing several tasks. Fortunately, In the Linux system, we have a console application \u201cscreen\u201d which allows us to use multiple terminal sessions in a window. Using \u201cscreen\u201d applications, it is possible to run any number of interactive command shells, console-based applications, etc. It is very useful to keep running the program even if you accidentally close the terminal.<\/p>\n<p>For instance, you are working in a remote Linux machine using an SSH session, but many times you get the SSH session terminated and you lose the task you are working on. In this case, the screen utility tool helps to resume the session. In this article, we will learn about the common usage of <strong>screens<\/strong> in Ubuntu 20.04.<\/p>\n<h2>Installation<\/h2>\n<p>Installation of the screen application is a simple and straightforward process. Run the following command to install screen in Ubuntu 20.04.<\/p>\n<pre>$ sudo apt-get update<\/pre>\n<pre>$ sudo apt-get install screen<\/pre>\n<p>To verify the installation of the screen, run the following command.<\/p>\n<pre>$ screen --version<\/pre>\n<p>Output:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"502\" height=\"114\" class=\"wp-image-6654\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/05\/word-image-261.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/05\/word-image-261.png 502w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/05\/word-image-261-300x68.png 300w\" sizes=\"auto, (max-width: 502px) 100vw, 502px\" \/><\/p>\n<h2>Start screen session<\/h2>\n<p>By using a simple screen command, the screen session can be started. The command will create a new terminal inside the current running terminal and if you do not want to use it you can use the exit command to come out of the screen.<\/p>\n<pre>$ screen<\/pre>\n<p>A new window can be started within the screen with the name as follows. In this example, I have used a screen name <em>example-screen<\/em> which can be reattached at a later stage.<\/p>\n<pre>$ screen -S example-screen<\/pre>\n<h2>List screen processes<\/h2>\n<p>We have started a new window using the screen command. Now to display all the current opened screens run the command:<\/p>\n<pre>$ screen -ls<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"858\" height=\"175\" class=\"wp-image-6655\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/05\/word-image-262.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/05\/word-image-262.png 858w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/05\/word-image-262-300x61.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/05\/word-image-262-768x157.png 768w\" sizes=\"auto, (max-width: 858px) 100vw, 858px\" \/><\/p>\n<h2>Detach the current screen<\/h2>\n<p>You can use ctrl+a followed by d command to detach your screen session from the current terminal. Type control+a d in the terminal session as :<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"699\" height=\"147\" class=\"wp-image-6656\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/05\/word-image-263.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/05\/word-image-263.png 699w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/05\/word-image-263-300x63.png 300w\" sizes=\"auto, (max-width: 699px) 100vw, 699px\" \/><\/p>\n<h2>Reattach the screen session<\/h2>\n<p>You can reattach your detached screen session using screen command with -r option. From the list of the screen session, you can simply type screen -r and screen name to reattach the session again. In this example, I have reattached an 4351.example-screen session from my screen list. You can select your session accordingly.<\/p>\n<pre>$ screen -r 4351.example-screen<\/pre>\n<p>You can also attach the screen session using ID of the screen session or using name only as:<\/p>\n<pre>$ screen -r 4351<\/pre>\n<pre>$ screen -r example-screen<\/pre>\n<h2>List screen parameters<\/h2>\n<p>You can list all the screen parameters using ctrl+a followed by character ? .<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1277\" height=\"534\" class=\"wp-image-6657\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/05\/word-image-264.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/05\/word-image-264.png 1277w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/05\/word-image-264-300x125.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/05\/word-image-264-1024x428.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/05\/word-image-264-768x321.png 768w\" sizes=\"auto, (max-width: 1277px) 100vw, 1277px\" \/><\/p>\n<h2>Split the screen vertically<\/h2>\n<p>The terminal window can be split either vertically or horizontally as per your convenience. To split the window vertically, press the ctrl + a followed by character | as in the screenshot. The same process can be repeated for n number of vertical screens.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1288\" height=\"400\" class=\"wp-image-6658\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/05\/word-image-265.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/05\/word-image-265.png 1288w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/05\/word-image-265-300x93.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/05\/word-image-265-1024x318.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/05\/word-image-265-768x239.png 768w\" sizes=\"auto, (max-width: 1288px) 100vw, 1288px\" \/><\/p>\n<p>To navigate to another screen type ctrl+a followed by Tab<\/p>\n<h2>Split the screen horizontally<\/h2>\n<p>To split the screen horizontally press ctrl + a followed by S (upper case). You can repeat the same process to get n number of horizontal screens.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1289\" height=\"454\" class=\"wp-image-6659\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/05\/word-image-266.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/05\/word-image-266.png 1289w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/05\/word-image-266-300x106.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/05\/word-image-266-1024x361.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/05\/word-image-266-768x270.png 768w\" sizes=\"auto, (max-width: 1289px) 100vw, 1289px\" \/><\/p>\n<h2>Unsplit the screen<\/h2>\n<p>Splitted screen either vertically or horizontally can be unsplited by pressing ctrl+a followed by Q (uppercase q)<\/p>\n<h2>Create a new terminal in split session<\/h2>\n<p>Just after splitting the screen horizontally or vertically, it does not create any terminal automatically.Move to the new terminal session using key ctrl+a followed by Tab and press ctrl+a followed by c (lowercase c) to create a new terminal session.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1286\" height=\"286\" class=\"wp-image-6660\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/05\/word-image-267.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/05\/word-image-267.png 1286w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/05\/word-image-267-300x67.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/05\/word-image-267-1024x228.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/05\/word-image-267-768x171.png 768w\" sizes=\"auto, (max-width: 1286px) 100vw, 1286px\" \/><\/p>\n<h2>Terminal screen session<\/h2>\n<p>To terminate the current screen session, press ctrl+a followed by k (lowercase k) as in the screenshot below.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"504\" height=\"97\" class=\"wp-image-6661\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/05\/word-image-268.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/05\/word-image-268.png 504w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/05\/word-image-268-300x58.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/05\/word-image-268-501x97.png 501w\" sizes=\"auto, (max-width: 504px) 100vw, 504px\" \/><\/p>\n<h2>Check all the options available with screen command<\/h2>\n<p>To check all the options available with screen command, run the following command in your terminal<\/p>\n<pre>$ screen --help<\/pre>\n<p>Output:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"900\" height=\"534\" class=\"wp-image-6662\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/05\/word-image-269.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/05\/word-image-269.png 900w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/05\/word-image-269-300x178.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/05\/word-image-269-768x456.png 768w\" sizes=\"auto, (max-width: 900px) 100vw, 900px\" \/><\/p>\n<h2>Check the owner of the screen<\/h2>\n<p>To check the owner of the opened screen session, you can list the content of the directory \/var\/run\/screen using ls -lthr \/var\/run\/screen command as:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"784\" height=\"145\" class=\"wp-image-6663\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/05\/word-image-270.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/05\/word-image-270.png 784w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/05\/word-image-270-300x55.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/05\/word-image-270-768x142.png 768w\" sizes=\"auto, (max-width: 784px) 100vw, 784px\" \/><\/p>\n<h2>Check the man page of Screen command<\/h2>\n<p>To check the man page of screen command, run <strong>man screen<\/strong> command as:<\/p>\n<pre>$ man screen<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1255\" height=\"305\" class=\"wp-image-6664\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/05\/word-image-271.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/05\/word-image-271.png 1255w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/05\/word-image-271-300x73.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/05\/word-image-271-1024x249.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/05\/word-image-271-768x187.png 768w\" sizes=\"auto, (max-width: 1255px) 100vw, 1255px\" \/><\/p>\n<h2>Conclusion<\/h2>\n<p>In this article, we have learned how to use screen commands in ubuntu 20.04. If you have more screen command tips, do not forget to share them in the comment below.<\/p>","protected":false},"excerpt":{"rendered":"<p>Sometimes we need to use multiple terminal sessions within one window while performing several tasks. Fortunately, In the Linux system, we have a console application \u201cscreen\u201d which allows&hellip;<\/p>","protected":false},"author":1,"featured_media":6712,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[352,351,100],"class_list":["post-6653","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ubuntu","tag-screen-command","tag-terminal-sessions","tag-ubuntu-20-04"],"_links":{"self":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/6653","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/comments?post=6653"}],"version-history":[{"count":1,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/6653\/revisions"}],"predecessor-version":[{"id":6711,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/6653\/revisions\/6711"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media\/6712"}],"wp:attachment":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media?parent=6653"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/categories?post=6653"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/tags?post=6653"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}