Skip to content

screen MacOS Command Guide

The screen command in MacOS allows users to create, manage, and navigate multiple terminal sessions with ease. It provides a virtual terminal window that persists even if the connection is lost. With screen, users can run processes in the background, detach from sessions, reattach to existing sessions, split the screen, and more. This command is particularly useful for managing tasks that require continuous monitoring or for running multiple commands simultaneously. By mastering the screen command, MacOS users can enhance their productivity and streamline their workflow when working in the terminal.

screen Syntax:

Terminal window
screen [options] [parameters]

Options:

OptionDescription
-SName the screen session
-lsList all screen sessions
-rReattach to a detached session
-dDetach a screen session
-XExecute a command within the session
-wipeRemove all dead sessions

Parameters:

ParameterDescription
sessionIDID of the session to attach or detach
commandCommand to execute within the screen session

screen Command Samples:

Create a New Screen Session

Terminal window
screen -S mysession

Creates a new screen session named “mysession”.

Detach from a Screen Session

Terminal window
screen -d mysession

Detaches from the screen session named “mysession”.

List all Screen Sessions

Terminal window
screen -ls

Lists all available screen sessions.

Reattach to a Screen Session

Terminal window
screen -r mysession

Reattaches to the screen session named “mysession”.

Split Screen Vertically

Terminal window
screen -v

Splits the screen vertically within the current session.

Split Screen Horizontally

Terminal window
screen -h

Splits the screen horizontally within the current session.

Change the Screen Session Name

Terminal window
screen -S newsession

Changes the name of the current screen session to “newsession”.

How do I start a new screen session in MacOS?

To start a new screen session in MacOS, use the following command:

Terminal window
screen

How do I list all screen sessions in MacOS?

To list all screen sessions in MacOS, execute the following command:

Terminal window
screen -ls

How do I reattach to a detached screen session in MacOS?

To reattach to a detached screen session in MacOS, use the following command:

Terminal window
screen -r <session_id>

How do I detach from a running screen session in MacOS?

To detach from a running screen session in MacOS without terminating it, execute the following key combination:

Terminal window
Ctrl + A, then press D

How do I terminate a screen session in MacOS?

To terminate a screen session in MacOS, use the following command while inside the session:

Terminal window
exit

How do I customize the screen session name in MacOS?

To customize the screen session name in MacOS when starting a new session, use the following command:

Terminal window
screen -S <session_name>

Applications of the screen command

  1. Running multiple terminal sessions
  2. Keeping processes running after closing a terminal
  3. Sharing terminal sessions with multiple users
  4. Running commands on a remote system
  5. Scripting automated tasks
  6. Monitoring and debugging processes