October 8, 2019

10+ ways How To Use Linux Screen

Did  you never faced the situation where you perform a very long-running task like recompile on a remote machine, and suddenly your internet connection drops, the SSH session is terminated, and your work is lost. Well, it will happen to most of us at some point, won’t it? Linux has a nice option for that, there is a utility, called “screen” that allows us to resume the sessions without losing any work.

GNU Screen is a terminal multiplexer. Basically, it means that you can start a screen session and then open any number of windows (virtual terminals) inside that session. So, you only have to open one SSH connection. If you use for example SecureCRT instead of Putty you can open SSH sessions on multiple servers. Processes running in “Screen” will continue to run when their window is not visible even if you get disconnected. If you get disconnected, you can easy connect to that screen again.

We can use “screen” is very different manners. The screen package is preinstalled on most Linux distros nowadays. First let’s check if it’s on our system. You can check if it is installed on your system by typing:

screen --version

Output should give a version number for example

Screen version 4.01.00devel (GNU) 2-May-06

If you don’t have screen installed on your system, you can  install it easily using the package manager of your Linux distribution.

Here are some examples most used.

sudo apt install screen
sudo yum install screen

To start a new screen session, it’s easy, just type “screen” in your console


This will open a new screen session, create a new window, and start a shell in that window. If your ssh drop you can re-connect again. But we have more option, give a screen a name. This I explain later and it’s easy to use if you have multiple screens running and want to re-connect or switch between them.

Now that you have opened a screen session, you can get a list of commands by typing:

Crtl+a ?

So, press Crtl+a and type ? Example.

Screen key bindings, page 1 of 1.

                       Command key:  ^A   Literal ^A:  a

  break       ^B b         license     ,            removebuf   =         
  clear       C            lockscreen  ^X x         reset       Z         
  colon       :            log         H            screen      ^C c      
  copy        ^[ [         login       L            select      '         
  detach      ^D d         meta        a            silence     _         
  digraph     ^V           monitor     M            split       S         
  displays    *            next        ^@ ^N sp n   suspend     ^Z z      
  dumptermcap .            number      N            time        ^T t      
  fit         F            only        Q            title       A         
  flow        ^F f         other       ^A           vbell       ^G        
  focus       ^I           pow_break   B            version     v         
  hardcopy    h            pow_detach  D            width       W         
  help        ?            prev        ^H ^P p ^?   windows     ^W w      
  history     { }          quit        \            wrap        ^R r      
  info        i            readbuf     <            writebuf    >         
  kill        K k          redisplay   ^L l         xoff        ^S s      
  lastmsg     ^M m         remove      X            xon         ^Q q      

^]   paste .
"    windowlist -b
-    select -
0    select 0
1    select 1
2    select 2
3    select 3
4    select 4
5    select 5
6    select 6
7    select 7
8    select 8
9    select 9
I    login on
O    login off
]    paste .
|    split -v
:kB: focus prev

                        [Press Space or Return to end.]

When screen is started, it reads its configuration parameters from /etc/screenrc and ~/.screenrc if the file is present. We can modify the default Screen settings according to our preferences using the .screenrc file.

Here is a sample ~/.screenrc configuration with customized status line and few additional options:

# Set scrollback buffer
defscrollback 200000

# Customize the status line
hardstatus alwayslastline
hardstatus string '%{= kG}[ %{G}%H %{g}][%= %{= kw}%?%-Lw%?%{r}(%{W}%n*%f%t%?(%u)%?%{r})%{w}%?%+Lw%?%?%= %{g}][%{B} %m-%d %{W}%c %{g}]'



Sorry, article not ready yet, more to come.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *