Linux screen command and detached session

Use the linux screen command to launch a detached session

How to launch a linux script from a distant console and detached from it so that it keeps working even if you close your terminal or turn off your computer.
The session is stored somewhere and you can recover it later.


These are the basic steps:

1. Open a session with the name you want


screen -S my_session



(In fact it opens a new shell)
 
2. Do whatever you want here
To make it simple try a ls command

3. Detache it from current session
    a) Ctrl-A and Ctrl-D, keep on holding the Ctrl key
    b) Another way to do it is by typing:


       screen -d my_session

    This will get you out from current session and you will see the message [detached from <pid>.my_session]
    You can disconnect from your terminal, turn off your computer, go and drink coffee..
    

4. List of running screen session


    screen -ls



5. Recover your detached session


    screen -r my_session


    You will find your old session still running here