detach screen linux code example

Example 1: bash how to use screen

# Note, screen is useful for continuing processes (e.g. downloads) on a
#	remote server without having to stay logged in to the server

# Basic syntax:
screen # This starts a new screen. 

# After starting a long process, e.g., a download, detach with:
CTRL+a d # To detach from screen, press CTRL+a, release, then press d

# To view active screens:
screen -ls # The first numbers by each screen indicate the screen_number

# To resume active screen:
screen -r # If there is only one active screen
screen -r screen_number # If there are multiple active screens

# To close a screen after detaching:
screen -X -S screen_number quit 

# View all CTRL+ commands available in screen:
CTRL+a ?

Example 2: reattach screen linux

-d -r   Reattach a session and if necessary detach it first.

-d -R   Reattach a session and if necessary detach or  even  create  it
               first.

-d -RR  Reattach  a  session  and if necessary detach or create it. Use
               the first session if more than one session is available.

-D -r   Reattach a session. If necessary  detach  and  logout  remotely
               first.