{"id":13246,"date":"2019-04-01T09:38:28","date_gmt":"2019-04-01T09:38:28","guid":{"rendered":"http:\/\/www.appservgrid.com\/paw92\/?p=13246"},"modified":"2019-04-01T09:38:28","modified_gmt":"2019-04-01T09:38:28","slug":"10-screen-command-examples-to-manage-linux-terminals","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/04\/01\/10-screen-command-examples-to-manage-linux-terminals\/","title":{"rendered":"10 Screen Command Examples to Manage Linux Terminals"},"content":{"rendered":"<p><strong>Screen<\/strong>\u00a0is a full-screen software program that can be used to multiplexes a physical console between several processes (typically interactive shells). It offers a user to open several separate terminal instances inside a one single terminal window manager.<\/p>\n<p>The screen application is very useful, if you are dealing with multiple programs from a command line interface and for separating programs from the terminal shell. It also allows you to share your sessions with others users and detach\/attach terminal sessions.<\/p>\n<div id=\"attachment_4390\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2013\/10\/Screen-Commands.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-4390\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2013\/10\/Screen-Commands.png\" alt=\"Linux Screen Commands\" width=\"435\" height=\"321\" aria-describedby=\"caption-attachment-4390\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-4390\" class=\"wp-caption-text\">Screen Command Examples<\/p>\n<\/div>\n<p>On my Ubuntu 10.04 Server Edition,\u00a0<strong>Screen<\/strong>\u00a0has been installed by default. But, in Linux Mint does not have screen installed by default, I need to install it first using\u00a0<strong>apt-get command<\/strong>\u00a0before using it. Please follow your distribution installation procedure to install screen.<\/p>\n<pre># apt-get install screen (On <strong>Debian<\/strong> based Systems)<\/pre>\n<pre># yum install screen (On <strong>RedHat<\/strong> based Systems)<\/pre>\n<p>Actually, Screen is a very good command in Linux which is hidden inside hundreds of Linux commands. Let\u2019s start to see the function of Screen.<\/p>\n<h3>Start screen for the first time<\/h3>\n<p>Just type screen at the command prompt. Then the screen will show with interface exactly as the command prompt.<\/p>\n<pre>pungki@mint ~ $ screen<\/pre>\n<h3>Show screen parameter<\/h3>\n<p>When you enter the screen, you can do all your work as you are in the normal CLI environment. But since the screen is an application, so it have command or parameters.<\/p>\n<p>Type \u201c<strong>Ctrl-A<\/strong>\u201d and \u201c<strong>?<\/strong>\u201d without quotes. Then you will see all commands or parameters on screen.<\/p>\n<pre>                                                             Screen key bindings, page 1 of 1.\r\n\r\n                                                             Command key:  ^A   Literal ^A:  a\r\n\r\n  break       ^B b         flow        ^F f         lockscreen  ^X x         pow_break   B            screen      ^C c         width       W\r\n  clear       C            focus       ^I           log         H            pow_detach  D            select      '            windows     ^W w\r\n  colon       :            hardcopy    h            login       L            prev        ^H ^P p ^?   silence     _            wrap        ^R r\r\n  copy        ^[ [         help        ?            meta        a            quit        \\            split       S            writebuf    &gt;\r\n  detach      ^D d         history     { }          monitor     M            readbuf     &lt;            suspend     ^Z z         xoff        ^S s\r\n  digraph     ^V           info        i            next        ^@ ^N sp n   redisplay   ^L l         time        ^T t         xon         ^Q q\r\n  displays    *            kill        K k          number      N            remove      X            title       A\r\n  dumptermcap .            lastmsg     ^M m         only        Q            removebuf   =            vbell       ^G\r\n  fit         F            license     ,            other       ^A           reset       Z            version     v\r\n\r\n^]  paste .\r\n\"   windowlist -b\r\n-   select -\r\n0   select 0\r\n1   select 1\r\n2   select 2\r\n3   select 3\r\n4   select 4\r\n5   select 5\r\n6   select 6\r\n7   select 7\r\n8   select 8\r\n9   select 9\r\nI   login on\r\nO   login off\r\n]   paste .<\/pre>\n<p>To get out of the help screen, you can press \u201cspace-bar\u201d button or \u201c<strong>Enter<\/strong>\u201c. (Please note that all shortcuts which use \u201c<strong>Ctrl-A<\/strong>\u201d is done without quotes).<\/p>\n<h3>Detach the screen<\/h3>\n<p>One of the advantages of screen that is you can detach it. Then, you can restore it without losing anything you have done on the screen. Here\u2019s the sample scenario:<\/p>\n<p>You are in the middle of\u00a0<strong>SSH-on<\/strong>\u00a0your server. Let\u2019s say that you are downloading\u00a0<strong>400MB<\/strong>\u00a0patch for your system using\u00a0<a href=\"https:\/\/www.tecmint.com\/10-wget-command-examples-in-linux\/\" target=\"_blank\" rel=\"noopener\">wget command<\/a>.<\/p>\n<p>The download process is estimated to take\u00a0<strong>2 hours<\/strong>\u00a0long. If you disconnect the\u00a0<strong>SSH<\/strong>\u00a0session, or suddenly the connection lost by accident, then the download process will stop. You have to start from the beginning again. To avoid that, we can use screen and detach it.<\/p>\n<p>Take a look at this command. First, you have to enter the screen.<\/p>\n<pre>pungki@mint ~ $ screen<\/pre>\n<p>Then you can do the download process. For examples on my Linux Mint, I am upgrading my\u00a0<strong>dpkg<\/strong>\u00a0package using\u00a0<strong>apt-get<\/strong>\u00a0command.<\/p>\n<pre>pungki@mint ~ $ sudo apt-get install dpkg<\/pre>\n<h5>Sample Output<\/h5>\n<pre>Reading package lists... Done\r\nBuilding dependency tree      \r\nReading state information... Done\r\nThe following packages will be upgraded:\r\n  dpkg\r\n1 upgraded, 0 newly installed, 0 to remove and 1146 not upgraded.\r\nNeed to get 2,583 kB of archives.\r\nAfter this operation, 127 kB of additional disk space will be used.\r\nGet:1 http:\/\/debian.linuxmint.com\/latest\/ testing\/main dpkg i386 1.16.10 [2,583 kB]\r\n47% [1 dpkg 1,625 kB\/2,583 kB 47%]                                        14,7 kB\/s<\/pre>\n<p>While downloading in progress, you can press \u201c<strong>Ctrl-A<\/strong>\u201d and \u201c<strong>d<\/strong>\u201c. You will not see anything when you press those buttons. The output will be like this:<\/p>\n<pre>[detached from 5561.pts-0.mint]\r\npungki@mint ~ $<\/pre>\n<h3>Re-attach the screen<\/h3>\n<p>After you detach the screen, let say you are disconnecting your\u00a0<strong>SSH<\/strong>\u00a0session and going home. In your home, you start to\u00a0<strong>SSH<\/strong>\u00a0again to your server and you want to see the progress of your download process. To do that, you need to restore the screen. You can run this command:<\/p>\n<pre>pungki@mint ~ $ screen -r<\/pre>\n<p>And you will see that the process you left is still running.<\/p>\n<p>When you have more than\u00a0<strong>1 screen<\/strong>\u00a0session, you need to type the screen session\u00a0<strong>ID<\/strong>. Use screen\u00a0<strong>-ls<\/strong>\u00a0to see how many screen are available.<\/p>\n<pre>pungki@mint ~ $ screen -ls<\/pre>\n<h5>Sample Output<\/h5>\n<pre>pungki@mint ~ $ screen -ls\r\nThere are screens on:\r\n        <strong>7849.pts-0.mint<\/strong> (10\/06\/2013 01:50:45 PM)        (Detached)\r\n        5561.pts-0.mint (10\/06\/2013 11:12:05 AM)        (Detached)\r\n2 Sockets in \/var\/run\/screen\/S-pungki<\/pre>\n<p>If you want to restore screen\u00a0<strong>7849.pts-0<\/strong>.mint, then type this command.<\/p>\n<pre>pungki@mint ~ $ screen -r 7849<\/pre>\n<h3>Using Multiple Screen<\/h3>\n<p>When you need more than\u00a0<strong>1 screen<\/strong>\u00a0to do your job, is it possible? Yes it is. You can run multiple screen window at the same time. There are 2 (two) ways to do it.<\/p>\n<p>First, you can detach the first screen and the run another screen on the real terminal. Second, you do nested screen.<\/p>\n<h3>Switching between screens<\/h3>\n<p>When you do nested screen, you can switch between screen using command \u201c<strong>Ctrl-A<\/strong>\u201d and \u201c<strong>n<\/strong>\u201c. It will be move to the next screen. When you need to go to the previous screen, just press \u201c<strong>Ctrl-A<\/strong>\u201d and \u201c<strong>p<\/strong>\u201c.<\/p>\n<p>To create a new screen window, just press \u201c<strong>Ctrl-A<\/strong>\u201d and \u201c<strong>c<\/strong>\u201c.<\/p>\n<h3>Logging whatever you do<\/h3>\n<p>Sometimes it is important to\u00a0<strong>record<\/strong>\u00a0what you have done while you are in the console. Let say you are a\u00a0<strong>Linux Administrator<\/strong>\u00a0who manage a lot of Linux servers.<\/p>\n<p>With this screen logging, you don\u2019t need to write down every single command that you have done. To activate screen logging function, just press \u201c<strong>Ctrl-A<\/strong>\u201d and \u201c<strong>H<\/strong>\u201c. (Please be careful, we use capital \u2018<strong>H<\/strong>\u2019 letter. Using non capital \u2018<strong>h<\/strong>\u2019, will only create a screenshot of screen in another file named hardcopy).<\/p>\n<p>At the bottom left of the screen, there will be a notification that tells you like: Creating logfile \u201c<strong>screenlog.0<\/strong>\u201c. You will find\u00a0<strong>screenlog.0<\/strong>\u00a0file in your home directory.<\/p>\n<p>This feature will append everything you do while you are in the screen window. To close screen to log running activity, press \u201c<strong>Ctrl-A<\/strong>\u201d and \u201c<strong>H<\/strong>\u201d again.<\/p>\n<p>Another way to activate logging feature, you can add the parameter \u201c<strong>-L<\/strong>\u201d when the first time running screen. The command will be like this.<\/p>\n<pre>pungki@mint ~ $ screen -L<\/pre>\n<h3>Lock screen<\/h3>\n<p>Screen also have shortcut to\u00a0<strong>lock<\/strong>\u00a0the screen. You can press \u201c<strong>Ctrl-A<\/strong>\u201d and \u201c<strong>x<\/strong>\u201d shortcut to lock the screen. This is handy if you want to lock your screen quickly. Here\u2019s a sample output of lock screen after you press the shortcut.<\/p>\n<pre>Screen used by Pungki Arianto  on mint.\r\nPassword:<\/pre>\n<p>You can use your Linux password to unlock it.<\/p>\n<h3>Add password to lock screen<\/h3>\n<p>For security reason, you may want to put the\u00a0<strong>password<\/strong>\u00a0to your screen session. A Password will be asked whenever you want to\u00a0<strong>re-attach<\/strong>\u00a0the screen. This password is different with\u00a0<strong>Lock Screen<\/strong>\u00a0mechanism above.<\/p>\n<p>To make your screen password protected, you can edit \u201c<strong>$HOME\/.screenrc<\/strong>\u201d file. If the file doesn\u2019t exist, you can create it manually. The syntax will be like this.<\/p>\n<pre>password crypt_password<\/pre>\n<p>To create \u201c<strong>crypt_password<\/strong>\u201d above, you can use \u201c<strong>mkpasswd<\/strong>\u201d command on Linux. Here\u2019s the command with password \u201c<strong>pungki123<\/strong>\u201c.<\/p>\n<pre>pungki@mint ~ $ mkpasswd pungki123\r\nl2BIBzvIeQNOs<\/pre>\n<p><strong>mkpasswd<\/strong>\u00a0will generate a hash password as shown above. Once you get the hash password, you can copy it into your \u201c<strong>.screenrc<\/strong>\u201d file and save it. So the \u201c<strong>.screenrc<\/strong>\u201d file will be like this.<\/p>\n<pre>password l2BIBzvIeQNOs<\/pre>\n<p>Next time you run screen and detach it, password will be asked when you try to\u00a0<strong>re-attach<\/strong>\u00a0it, as shown below:<\/p>\n<pre>pungki@mint ~ $ screen -r 5741\r\nScreen password:<\/pre>\n<p>Type your password, which is \u201c<strong>pungki123<\/strong>\u201d and the screen will\u00a0<strong>re-attach<\/strong>\u00a0again.<\/p>\n<p>After you implement this screen password and you press \u201c<strong>Ctrl-A<\/strong>\u201d and \u201c<strong>x<\/strong>\u201d , then the output will be like this.<\/p>\n<pre>Screen used by Pungki Arianto  on mint.\r\nPassword:\r\nScreen password:<\/pre>\n<p>A Password will be asked to you\u00a0<strong>twice<\/strong>. First password is your\u00a0<strong>Linux password<\/strong>, and the second password is the password that you put in your\u00a0<strong>.screenrc<\/strong>\u00a0file.<\/p>\n<h3>Leaving Screen<\/h3>\n<p>There are\u00a0<strong>2<\/strong>\u00a0(two) ways to leaving the screen. First, we are using \u201c<strong>Ctrl-A<\/strong>\u201d and \u201c<strong>d<\/strong>\u201d to detach the screen. Second, we can use the exit command to terminating screen. You also can use \u201c<strong>Ctrl-A<\/strong>\u201d and \u201c<strong>K<\/strong>\u201d to kill the screen.<\/p>\n<p>That\u2019s some of screen usage on daily basis. There are still a lot of features inside the\u00a0<strong>screen command<\/strong>. You may see\u00a0<strong>screen man page<\/strong>\u00a0for more detail.<\/p>\n<p><a href=\"https:\/\/www.tecmint.com\/screen-command-examples-to-manage-linux-terminals\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Screen\u00a0is a full-screen software program that can be used to multiplexes a physical console between several processes (typically interactive shells). It offers a user to open several separate terminal instances inside a one single terminal window manager. The screen application is very useful, if you are dealing with multiple programs from a command line interface &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/04\/01\/10-screen-command-examples-to-manage-linux-terminals\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;10 Screen Command Examples to Manage Linux Terminals&#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-13246","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\/13246","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=13246"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/13246\/revisions"}],"predecessor-version":[{"id":13247,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/13246\/revisions\/13247"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=13246"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=13246"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=13246"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}