> For the complete documentation index, see [llms.txt](https://linux-tutorial-cli.gitbook.io/linux-cli-tutorial/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://linux-tutorial-cli.gitbook.io/linux-cli-tutorial/txt-files/screen.md).

# screen

## screen

The `screen` command in Unix and Linux is used to create and manage multiple terminal sessions within a single terminal window or SSH session. It provides a way to multiplex a physical terminal between several processes, typically interactive command-line sessions.

#### Basic Usage

To start a new `screen` session:

```sh
screen
```

This command starts a new session and opens a shell prompt within it. From this new screen session, you can start running commands and managing multiple terminal windows.

#### Key Commands in `screen`

Once inside a `screen` session, you can use various key commands to manage multiple windows, detach sessions, and reattach to them later:

* **Create a new window**: Press `Ctrl` + `a`, then `c`.
* **Switch between windows**: Press `Ctrl` + `a`, then `n` (next window) or `p` (previous window).
* **Detach from screen session**: Press `Ctrl` + `a`, then `d`.
* **List windows**: Press `Ctrl` + `a`, then `"` (lists all windows for selection).
* **Attach to a detached session**: Use `screen -r` followed by the session ID, or simply `screen -r` to reattach to the last session.

#### Examples

**Starting a `screen` session and running commands**

1. Start a new `screen` session:

   ```sh
   screen
   ```
2. Inside the screen session, run commands as usual:

   ```sh
   ls -l
   cd /path/to/directory
   ```
3. Create a new window within `screen`:
   * Press `Ctrl` + `a`, then `c`.
   * You are now in a new shell within `screen`.
4. Switch between windows:
   * Press `Ctrl` + `a`, then `n` to move to the next window.
   * Press `Ctrl` + `a`, then `p` to move to the previous window.
5. Detach from the `screen` session:
   * Press `Ctrl` + `a`, then `d`.
   * This leaves the `screen` session running in the background.
6. Reattach to the detached `screen` session:
   * Use `screen -r` to reattach to the last detached session.

#### Practical Use Cases

**Remote Sessions**

`screen` is invaluable for managing long-running processes or sessions on remote servers. If the SSH connection drops, `screen` ensures that your session continues running in the background, and you can reattach to it later.

**Managing Multiple Tasks**

With `screen`, you can multitask within a single terminal window, switching between different tasks or shells without opening multiple terminal windows.

**Script Automation**

Automate tasks and scripts within `screen` sessions, ensuring that they run continuously even when disconnected from the terminal.

#### Summary

The `screen` command is a powerful tool for managing multiple terminal sessions within a single terminal window or SSH session in Unix and Linux. It allows you to detach and reattach sessions, manage multiple tasks simultaneously, and keep processes running in the background even if the terminal session is terminated. Understanding its key commands and usage can significantly improve your workflow efficiency, especially in remote server management and multitasking environments.

## help

```
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://linux-tutorial-cli.gitbook.io/linux-cli-tutorial/txt-files/screen.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
