Henry
发布于 2024-12-25 / 57 阅读
0
0

Screen - 安装和简介

功能描述

使用 Screen 进行多会话管理,且在连接断开时保持会话的执行。

安装

~$ sudo apt install screen
[sudo] password for henrylin:               
正在读取软件包列表... 完成
正在分析软件包的依赖关系树... 完成
正在读取状态信息... 完成                 
将会同时安装下列软件:
  libutempter0
建议安装:
  byobu | screenie | iselect
下列【新】软件包将被安装:
  libutempter0 screen
升级了 0 个软件包,新安装了 2 个软件包,要卸载 0 个软件包,有 0 个软件包未被升级。
需要下载 665 kB 的归档。
解压缩后会消耗 1,072 kB 的额外空间。
您希望继续执行吗? [Y/n] y
获取:1 http://mirrors.aliyun.com/ubuntu noble/main amd64 libutempter0 amd64 1.2.1-3build1 [9,606 B]
获取:2 http://mirrors.aliyun.com/ubuntu noble/main amd64 screen amd64 4.9.1-1build1 [655 kB]
已下载 665 kB,耗时 0秒 (1,579 kB/s)
正在选中未选择的软件包 libutempter0:amd64。
(正在读取数据库 ... 系统当前共安装有 538659 个文件和目录。)
准备解压 .../libutempter0_1.2.1-3build1_amd64.deb  ...
正在解压 libutempter0:amd64 (1.2.1-3build1) ...
正在选中未选择的软件包 screen。
准备解压 .../screen_4.9.1-1build1_amd64.deb  ...
正在解压 screen (4.9.1-1build1) ...
正在设置 libutempter0:amd64 (1.2.1-3build1) ...
正在设置 screen (4.9.1-1build1) ...
正在处理用于 debianutils (5.17build1) 的触发器 ...
正在处理用于 install-info (7.1-3build2) 的触发器 ...
正在处理用于 libc-bin (2.39-0ubuntu8.3) 的触发器 ...
正在处理用于 man-db (2.12.0-4build2) 的触发器 ...

功能使用简介

  • 会话持久性:即使在网络连接断开或终端关闭的情况下,screen 也可以保持会话运行。这意味着你可以重新连接到之前断开的会话,继续你的工作。
  • 多窗口管理:screen 允许你在单个终端窗口中创建和管理多个会话窗口,每个窗口都可以运行不同的程序。
  • 会话共享:screen 允许多个用户连接到同一个会话,这对于协作非常有用。
  • 会话分离:你可以将当前会话从终端分离,即使终端关闭,会话也会在后台继续运行。
  • 会话日志:screen 可以记录会话输出到日志文件,这对于调试和审计非常有用。
  • 定制和配置:screen 允许用户自定义键盘绑定、窗口标题、以及其他选项,以适应个人偏好。

创建 新窗口

~$ screen -S test_screen

查看 screen 窗口列表

~$ screen -ls
There is a screen on:
        265873.test_screen      (2024年12月17日 16时10分52秒)   (Attached)
1 Socket in /run/screen/S-henrylin.

退出 窗口 但不结束当前会话  - Ctrl + A + D三个按键同时按下

~$ screen -S test_screen
[detached from 265873.test_screen]

重新连接会话

~$ screen -r test_screen

结束会话

~$ exit
~$ screen -r test_screen
[screen is terminating]

帮助文档

~$ screen --help
Use: screen [-opts] [cmd [args]]
 or: screen -r [host.tty]

Options:
-4            Resolve hostnames only to IPv4 addresses.
-6            Resolve hostnames only to IPv6 addresses.
-a            Force all capabilities into each window's termcap.
-A -[r|R]     Adapt all windows to the new display width & height.
-c file       Read configuration file instead of '.screenrc'.
-d (-r)       Detach the elsewhere running screen (and reattach here).
-dmS name     Start as daemon: Screen session in detached mode.
-D (-r)       Detach and logout remote (and reattach here).
-D -RR        Do whatever is needed to get a screen session.
-e xy         Change command characters.
-f            Flow control on, -fn = off, -fa = auto.
-h lines      Set the size of the scrollback history buffer.
-i            Interrupt output sooner when flow control is on.
-l            Login mode on (update /var/run/utmp), -ln = off.
-ls [match]   or
-list         Do nothing, just list our SockDir [on possible matches].
-L            Turn on output logging.
-Logfile file Set logfile name.
-m            ignore $STY variable, do create a new screen session.
-O            Choose optimal output rather than exact vt100 emulation.
-p window     Preselect the named window if it exists.
-q            Quiet startup. Exits with non-zero return code if unsuccessful.
-Q            Commands will send the response to the stdout of the querying process.
-r [session]  Reattach to a detached screen process.
-R            Reattach if possible, otherwise start a new session.
-s shell      Shell to execute rather than $SHELL.
-S sockname   Name this session <pid>.sockname instead of <pid>.<tty>.<host>.
-t title      Set title. (window's name).
-T term       Use term as $TERM for windows, rather than "screen".
-U            Tell screen to use UTF-8 encoding.
-v            Print "Screen version 4.09.01 (GNU) 20-Aug-23".
-wipe [match] Do nothing, just clean up SockDir [on possible matches].
-x            Attach to a not detached screen. (Multi display mode).
-X            Execute <cmd> as a screen command in the specified session.

评论