Screen on Linux is a popular command-line program that lets you multiplex between interactive shells.
What that means is, you can use
screen to save and restore running of commands.
Screen in action
The best way to test this out is to SSH into a server.
At this stage, you can execute
man screen to learn all the commands available to you.
You can issue a
screen -list to show all screen sessions that may already be open.
If there are no sessions, then you can simply begin by typing
screen and hitting
You will be presented with this the first time around, you can press
Return to continue at any time.
Now you can execute some long-running script or otherwise over SSH and not worry about being timed-out, logged out or cut off midway.
A followed by
D to exit out while saving the state.
Listing, Retrieving and Destroying Shells
Now in the parent shell, type
screen -list one more time to see the shell still active, that can be rejoined.
If there is only one entry in this list, type
screen -r to rejoin it, otherwise, type
screen -r <PTRR_ID>.
For example in the above
screen -r 3560.pts-0.server.
To terminate a shell session, simply go into and press
D to destroy it. Now if you type
screen -list once again, there will be no sessions, just how it started out.