Saturday, December 30, 2006

Screen Utility for Linux

In unix like operating systems we have the 'screen' utility,
so usefull as easy to use. In cases where you need to
compile a kernel in the background in a remote server
(where the connection can get lost), download a file or
do some critical operation without the risk of loosing
the network connection to the server, the 'screen' utility
comes handy.

Run it just writing its name:
#screen

This creates a virtual shell, a virtual terminal,
for those (like me) that love virtualization :-)
Now you see a new shell, type some commands,
leave a 'top' running, and type:

ctrl+a+c (this creates a new window, like a new shell).

How to go back to the window with the 'top' ?
Type ctrl+a+n (this jumps to the next window,
in this case, the first one).

I dont know of a limit of shells you can
create with "ctrl+a+c".
You jump backward to the previous window
with "ctrl+a+p".
Split the current 'screen' window in multiple
windows with "ctrl+a+S"
Jump between splitted windows with "ctrl+a+TAB".

And, if you need to send the the terminal the "ctrl+a" signal, press "ctrl+a+a".

Now... the real magic, how to leave this process running in the background and how to recover the terminal after a connection loose ?

Press ctrl+a+d to disconnect from 'screen' and leave
all the terminals in the background, these processes
will survive as i said, a disconnection, so you can
disconnect from that server and come back in two days
that screen will be still there.

This shows something like:

[root@sriram ~]# screen -ls
There is a screen on:
2131.pts-1.sriram (Detached)
1 Socket in /var/run/screen/S-root.

To re-connect to screen write:
[root@sriram ~]# screen -r 2131.pts-1.sriram

And you are back in the screen terminals.

I hope it was usefull, please leave me a
message with your experience or new tricks.

No comments: