**1. Installation**
The `screen` command is usually pre-installed on most CentOS systems. However, if it's missing, you can install it using the `yum` package manager:
```bash
sudo yum install screen
# If prompt the screen command is not found
sudo dnf install epel-release
```
**2. Starting a New Screen Session**
To start a new screen session, simply type the following command in your terminal:
```bash
screen
```
This will create a new detached session, meaning it runs in the background even if you close your terminal window.
**3. Working Within a Screen Session**
Once you're inside a screen session, you can use your terminal as usual. You can run commands, navigate directories, and work on your tasks.
**4. Navigating Screen Sessions**
There are several ways to manage and navigate screen sessions:
* **Listing Existing Sessions:**
```bash
screen -ls
```
This command lists all active screen sessions with their session IDs and names (if set).
* **Detaching from a Session:**
There are two ways to detach from a screen session, leaving it running in the background:
* **Using `Ctrl+a` followed by `d`:**
This is the most common way. Press `Ctrl+a` (hold Control and press a), then release both keys and press `d`.
* **Using `exit`:**
If you're within a shell within the screen session, you can simply type `exit`.
* **Reattaching to a Session:**
To reattach to a detached screen session, use the following command, replacing `<session_id>` with the actual ID from the `screen -ls` output:
```bash
screen -r <session_id>
```
**5. Screen Commands within a Session**
Once you're inside a screen session, you can use several commands by pressing `Ctrl+a` followed by a key:
* **Create a new window:** `Ctrl+a` then `c`
* **Switch between windows:** `Ctrl+a` then number (e.g., `1`, `2`, etc.)
* **List all windows:** `Ctrl+a` then `w`
* **Kill the current window:** `Ctrl+a` then `x`
* **Detach from the session:** `Ctrl+a` then `d`
**6. Renaming a Screen Session**
By default, screen sessions have generic names. You can rename a session using the following command within the session:
```bash
screen -S <new_name>
```
Replace `<new_name>` with your desired session name.
**7. Quitting Screen Completely**
To completely quit a screen session and terminate all running processes within it, use the following command while detached (replace `<session_id>` with the actual ID):
```bash
screen -S -Q quit <session_id>
```
**8. Additional Tips**
* You can configure various screen settings using the `screenrc` file located in your home directory (`~/.screenrc`).
* Screen allows you to split the terminal window into multiple panes within a single session. Refer to the `screen` man page (`man screen`) for more details on advanced features.
I hope this comprehensive tutorial helps you effectively use the `screen` command in CentOS!