simple examples of how to

Wednesday, November 2, 2011

[Linux] screen simple how to by example

Assume you have 'a remote' and 'a local'.

At the remote, you access via ssh and launch 'screen -S test'.
Then, you will see a terminal-look which is no difference, but in background, there are lot of difference.
First, this terminal-look is not the ssh session that you connect but the session stored in the remote itself (i.e., screen session).
The difference is that although the ssh session dies unexpectedly, screen session does not die.

You can whenever connect this session by screen command.
Here are the most frequently used screen commands

screen -S test (create a new screen session named as 'test')
screen -ls (list the currently created screen sessions)
the results would look like this

16373.test1 (11/03/2011 10:29:08 AM) (Multi, detached)
15342.test2 (11/03/2011 10:30:08 AM) (Multi, attached)

Multi means that multiple attachments are possible.
Attached means that this session is already attached by someone.
If you want to join the attached session, you should use screen -x.
If you want to join the detached session, you should use screen -r.
For example

$ screen -r test1 #reattaching screen session
$ screen -x test2 #attach the currently attached screen session (it looks like a remote desktop of terminal version)
In order to use screen -x, make sure that it is Multi.

At the screen session, if you type 'exit' then the screen session quits.
If you just want to leave the session without quiting it, you type Ctrl+A and d.
it means Detaching from the current screen session.

No comments:

Post a Comment