2

linux 中 screen 的使用

 1 year ago
source link: https://xujinzh.github.io/2023/02/20/linux-screen-useage/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

通过终端在远程服务器上执行长时间运行的任务时,因为突然的断开导致 SSH 会话终止,使得程序运行失败!使用 screen 能够避免上面情况的发生。同时,让我们在一个终端上可以运行多个终端程序,并可以自由切换这些终端。

Screen 或 GNU Screen 是一个终端多路复用器。换句话说,这意味着您可以启动一个屏幕会话,然后在该会话中打开任意数量的窗口(虚拟终端)。在 Screen 中运行的进程在它们的窗口不可见时将继续运行,即使您断开连接也是如此。

安装 screen

Debian or Ubuntu 操作系统安装方法如下:

sudo apt update
sudo apt install screen -y

RedHat or CentOS or Fedora 操作系统安装方法如下:

sudo yum install screen

使用 screen

# 创建一个名字为 main 的 screen 终端
screen -S main

# 查看打开了哪些 screen 终端
screen -ls

# 退出名字为 main 的 screen 终端,也可以不用名字,采用 screen -ls 罗列的 screen 进程 id
screen -d main
# 如果终端上正在运行程序,可以采用快捷键 "ctrl + a, d" 退出终端

# 重新进入名字为 main 的 screen 终端
screen -r main

# 清理死掉的 screen
screen -wipe

# 查看当前终端是哪个 screen
echo $STY

以下是一些用于管理 Linux Screen 窗口的最常用快捷键:

Ctrl+a c      Create a new window (with shell).
Ctrl+a " List all windows.
Ctrl+a 0 Switch to window 0 (by number).
Ctrl+a A Rename the current window.
Ctrl+a S Split current region horizontally into two regions.
Ctrl+a | Split current region vertically into two regions.
Ctrl+a tab Switch the input focus to the next region.
Ctrl+a Ctrl+a Toggle between the current and previous windows
Ctrl+a Q Close all regions but the current one.
Ctrl+a X Close the current region.

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK