Screen is a small linux utility which can help you run long-running jobs in remote shell without worrying about loosing network connection.
Once a process is started inside screen session, if your network connection breaks or you choose to close terminal (without exit), you can resume into that screen session anytime from anywhere.
Install screen
apt-get install screen
Screen Commands
Create a screen
You can specify a name
screen -S name
Or even create screen without name
screen
Detach a screen
Never use “exit” inside screen. It will end “screen” session.
You keyboard shortcut CTRL+A+D
List Screens
Run
screen -ls
You will see
There are screens on:
7142.name (10/19/13 12:43:39) (Detached)
7127.pts-0.test3 (10/19/13 12:42:25) (Detached)
2 Sockets in /var/run/screen/S-root.
pts-0.test3
is name of screen which was created without specifying screen name explicitly.
Reattatch a screen
Run following to reattach a detached screen
screen -r name
Of specify -d
flag to force detach on a screen attached elsewhere
screen -d -r name
As you can create screens with same name, in case you have screen with same, you need to specify pid like below:
screen -r 7142
Create a new screen within a screen
I never needed this myself, but its possible to create CTRL+A+C
You can also create a new screen using normal screen -S name
command.