# 用 screen 管理多終端

<div align="left"><img src="https://529150212-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Lh81JtaIQ84bwQqz_Wh%2F-LrXjWotVi93BDD1S3I0%2F-LrXq5X84JUh9-14dq8A%2Fimage.png?alt=media&#x26;token=ecc24fd9-e0c0-4d7e-bb1d-35b6120e410d" alt=""></div>

sudo apt update&#x20;

sudo apt install screen&#x20;

在終端機中執行screen

通過C-a ?來查看所有的鍵

練習水平分割終端畫面 C-a S -> C-a tab -> C-a c

在分割畫面中捲動視窗 C-a esc -> 方向鍵

Detach 按下 Ctrl + a 後，再按下 d 鍵（detach），這時候整個 screen 就會被卸離，然後出現類似 \[detached from 17159.pts-1.ubuntu]

screen -ls 列出被detach的screen There are several suitable screens on: 17851.pts-1.ubuntu (2018年06月06日 09時26分15秒) (Detached) 17159.pts-1.ubuntu (2018年06月06日 09時21分24秒) (Detached)

screen -r PID -> screen -r 17851

Kill screen detached session:

screen -S 17851 -X quit screen -ls No Sockets found in /run/screen/S-pi.

> #### `screen` 操作指令表

| `screen` 參數                                  | 說明                                                                                                           |
| -------------------------------------------- | ------------------------------------------------------------------------------------------------------------ |
| `Ctrl` + `a` 與 `c`                           | 建立新 `screen` 視窗                                                                                              |
| `Ctrl` + `a` 與 `Ctrl` + `a`                  | 切換至上一個 `screen` 視窗                                                                                           |
| `Ctrl` + `a` 與數字鍵 `0` 到 `9`                  | 切換至指定編號的 `screen` 視窗                                                                                         |
| `Ctrl` + `a` 與 `n`                           | 切換至下一個的 `screen` 視窗                                                                                          |
| `Ctrl` + `a` 與 `p`                           | 切換至下一個的 `screen` 視窗                                                                                          |
| `Ctrl` + `a` 與 `w`                           | 列出目前所有的 `screen` 視窗                                                                                          |
| `Ctrl` + `a` 與 `"`                           | 列出目前所有的 `screen` 視窗，並可用上下鍵選擇要切換的設窗                                                                           |
| `Ctrl` + `a` 與 `k`                           | 關閉目前的 `screen` 視窗                                                                                            |
| `Ctrl` + `a` 與 `d`                           | 卸離 `screen` 工作環境                                                                                             |
| `Ctrl` + `a` 與 `Esc` 鍵（或 `Ctrl` + `a` 與 `[`） | 進入複製模式（copy mode），可用方向鍵操作捲軸，或用 `/` 與 `?` 來搜尋，按下空白鍵開始選取要複製的內容，選取完成後再按下第二次空白鍵，即可複製，隨後使用 `Ctrl` + `]` 可貼上複製的內容。 |
| `Ctrl` + `a` 與 `S`                           | 將畫面分割成上下兩個區域                                                                                                 |
| `Ctrl` + `a` 與 `Q`                           | 關閉分割畫面                                                                                                       |
| `Ctrl` + `a` 與 `Tab` 鍵                       | 切換分割畫面                                                                                                       |
| `Ctrl` + `a` 與 `t`                           | 顯示目前系統的時間與負載狀況                                                                                               |
| `Ctrl` + `a` 與 `a`                           | 送出 `Ctrl` + `a`                                                                                              |
| `Ctrl` + `a` 與 `?`                           | 顯示說明                                                                                                         |
| `Ctrl` + `a` 與 `v`                           | 顯示版本資訊                                                                                                       |
| `Ctrl` + `a` 與 `x`                           | 鎖定 `screen` 螢幕                                                                                               |
| `Ctrl` + `a` 與 `H`                           | 開啟或結束 `screen` 紀錄功能                                                                                          |
| `Ctrl` + `a` 與 `C`                           | 清除 `screen` 視窗中的內容                                                                                           |
| `Ctrl` + `a`、`D` 與 `D`                       | 強力卸離，卸離 `screen` 工作環境之後，直接登出                                                                                 |
| `Ctrl` + `a` 與 `Ctrl` + `g`                  | 視覺化鈴聲（visual bell）切換                                                                                         |
| `Ctrl` + `a` 與 `i`                           | 顯示目前 `screen` 視窗的資訊                                                                                          |
| `Ctrl` + `a` 與 `l`                           | 重繪目前 `screen` 視窗的內容                                                                                          |


---

# Agent Instructions: 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:

```
GET https://kawsing.gitbook.io/opensystem/andoid-shou-ji/untitled-4/linux-cli/yong-screen-guan-li-duo-zhong-duan.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
