How to Use the Screen Command in Linux
This command is used to create a new session inside your current session. It typically is used to run long-running process. The process will continue to run even if current session is terminated whether due to bad connection or an exit. It can be used to log in to a specific session and resume the process where it’s left off.
General syntax for screen
command:
screen [OPTIONS] [SESSION NAME]
Create a session with specified name
screen -S [file]
The -S
option creates a new window within the screen and names it.
Example: Let’s name our session “newexample” and start a new window.
List all screen processes
screen -ls
This option displays all currently open windows, including those running in the background.
Example: Typing the screen -ls
command to display the number of screens available.
Reattach the Terminal’s session
screen -r [filename]
Use this option to reattach a screen session which was detached in past.
Example: Reattaching the previously disconnected screen session named example.
Detach a session
screen -d [file]
The -d
option is used to detach the screen session, allowing it to be reattached later.
Example: Listing all currently attached screens and detaching the session named newfile.

Share a screen’s session
screen -X [sharing_session]
This option allows two people to log into the same account from different locations.
Example: The user called username is logging into the ubuntu account and connecting to the screen session newexample.