Using screen in a Bash terminal
We can use the screen (Manual here) facility to keep jobs running on the background in a remote server.
Starting a new screen with a name
The following creates a screen named my_screen.
screen -S my_screen
Listing all available screens
screen -ls
Will output something similar to:
There are screens on:
455780.another_screen (02/21/2024 07:24:46 PM) (Detached)
455604.my_screen (02/21/2024 07:24:41 PM) (Attached)
2 Sockets in /run/screen/S-mauricio.
Notice that my_screen is attached (currently active).
Detaching from a screen
You can detach a screen, and keep it running on the background, with Ctrl+A+D.
Reattaching to an existing screen
The following can be used to go back to a previously created screen named my_screen.
*Note: This will detach the screen from another existing session, if any.
screen -rd my_screen
If you do not give the screen a name when creating it, you can reattach to it using its id (see the screen -ls above to find the screen id):
screen -rd 455780
Exiting (closing) a screen
You can close a screen with Ctrl+D. This will terminate the screen permanently, that is, you will not be able to reattach to it.