I have recently be introduced to the *nix screen command. Incredibly powerful tool for managing windows which mulitplexes a physical terminal between one or many processes. One of the uses it to maintain interactive shells on a remote server between remote connections to the machine.
It is enormously helpful when executing long running commands on remote servers. Especially those that timeout your ssh connection and or from machines that you are going to either disconnect from the net or shutdown.
Basically, it allows you to create a session from which you can detach and then attach from a shell that you will then exit. It is an alternative for using nohup and provides the added benefit that you can reconnect to the command-line session.
Following is my current cheat sheet of notes regarding it’s usage. Full details can be found searching the web for tutorials and reading the man page.
. C-a = Control+A
. C-D = Control+D
. Create a screen:
$ screen -S [session-name]
. Detach from screen:
$ C-a d
. Terminate a screen session (from within the screen session):
$ C-a k
. List screens (from within a standard shell session):
$ screen -ls
. Connect to an existing screen:
$ screen -r [session-name]
. If there is only one screen and no session-name is given it will connect to it
. Re-connect to an ‘attached’ screen: This sometimes happen if you kill the window you are in without first detaching from the screen session
$ screen -d -r [session-name]
. Split screens:
. Create two named screen sessions:
. Enter one of the screens via $ screen -r [session-name]
. Horizontal split (once in a screen):
$ C-a S
. Move to next region:
$ C-a tab
. In the new region, (there will be no command prompt in a newly created region)
. Create a new session (this seems to create a new un-named session):
. C-a c
. Return to full-size screen:
. Switch to the half you want to keep
. $ C-a Q