惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

WordPress大学
WordPress大学
The GitHub Blog
The GitHub Blog
F
Fortinet All Blogs
Cloudbric
Cloudbric
P
Palo Alto Networks Blog
T
Threatpost
T
Tor Project blog
T
Tenable Blog
AWS News Blog
AWS News Blog
Project Zero
Project Zero
L
LangChain Blog
Cyberwarzone
Cyberwarzone
Engineering at Meta
Engineering at Meta
雷峰网
雷峰网
C
CERT Recently Published Vulnerability Notes
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Security Latest
Security Latest
云风的 BLOG
云风的 BLOG
I
Intezer
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
P
Proofpoint News Feed
A
Arctic Wolf
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Google DeepMind News
Google DeepMind News
V
Vulnerabilities – Threatpost
C
Cybersecurity and Infrastructure Security Agency CISA
MongoDB | Blog
MongoDB | Blog
aimingoo的专栏
aimingoo的专栏
K
Kaspersky official blog
Jina AI
Jina AI
N
News | PayPal Newsroom
T
The Blog of Author Tim Ferriss
D
DataBreaches.Net
A
About on SuperTechFans
博客园 - 三生石上(FineUI控件)
博客园 - 【当耐特】
Hugging Face - Blog
Hugging Face - Blog
Recorded Future
Recorded Future
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
S
Secure Thoughts
TaoSecurity Blog
TaoSecurity Blog
P
Privacy & Cybersecurity Law Blog
P
Proofpoint News Feed
MyScale Blog
MyScale Blog
IT之家
IT之家
Forbes - Security
Forbes - Security
The Hacker News
The Hacker News
Last Week in AI
Last Week in AI
T
Threat Research - Cisco Blogs
Y
Y Combinator Blog

博客园 - Nihaorz

告别闪烁,拥抱流畅:在 Windows Terminal 中完美配置 Cygwin 环境 Nginx 透明代理 + 自动回源存储:访问即缓存,落盘即文件 创建 docker ipvlan,让 docke 容器获取独立ip 电犀牛 R68s iStoreOS 2.5G 网口速率优化 解决 openwrt ssh 命令行终端 home、end 键不可用问题 一键添加视频封面脚本 ffmpeg 转码参数 docker save 远程 ssh 主机直接 load,不产生本地文件 AutoHotKey 脚本 - win10 自动连接无线显示器 SSH 登录/退出实时监控脚本 OpenClaw 安装部署,配置 deepseek curl 断点续传下载 debian iso 镜像下载地址 linux 安装 zerotier,加入网络 基于 Fail2ban 的 SSH 入侵自动反制方案 ssh 配置密钥登录,关闭密码登录 memc - 基于 shell 的交互式清理内存脚本 基于 Fail2ban 的 OpenWRT SSH 入侵自动反制方案 使用 ofelia 在 docker 容器中执行计划任务 linux 磁盘挂载示例
Linux Screen 命令速查
Nihaorz · 2026-03-02 · via 博客园 - Nihaorz

screen 是一个终端多路复用器,让你在一个 SSH 会话中管理多个窗口,即使断网也不怕任务中断。

# 创建新会话(-S 指定名称,进入会话后再执行命令)
screen -S iso-down

# 在会话中执行命令(后台下载示例)
screen -S iso-down curl -OL https://releases.ubuntu.com/24.04/ubuntu-24.04.3-live-server-amd64.iso

# 列出所有会话
screen -ls

# 恢复(重新连接)会话
screen -r iso-down

# 强制退出指定会话
screen -X -S iso-down quit

退出方式对比

方式命令/操作说明
临时退出 Ctrl+A 再按 D detach 分离会话,任务后台继续运行
彻底关闭 exit 或 Ctrl+D 会话内所有进程结束后自动关闭
强制杀死 screen -X -S name quit 从外部强制终止会话及所有进程

为什么用 Screen?

  • 防断连:SSH 断开不影响后台任务

  • 多窗口:单终端管理多个任务

  • 可恢复:随时重连查看进度

适合场景:大文件下载、编译、长时间脚本运行。

实用技巧:快速检测是否在 Screen 中

创建快捷脚本 /usr/local/bin/isscreen

#!/bin/bash
if [ -n "$STY" ]; then
    echo "✅  当前在 screen 会话中: $STY"
else
    echo "❌  不在 screen 会话中"
fi

使用方法:

# 1. 创建并写入脚本
sudo tee /usr/local/bin/isscreen << 'EOF'
#!/bin/bash
if [ -n "$STY" ]; then
    echo "✅  当前在 screen 会话中: $STY"
else
    echo "❌  不在 screen 会话中"
fi
EOF

# 2. 添加执行权限
sudo chmod +x /usr/local/bin/isscreen

# 3. 随时检测
isscreen

效果示例:

$ isscreen
❌  不在 screen 会话中

$ screen -S work
$ isscreen
✅  当前在 screen 会话中: 4132302.work

原理:$STY 是 screen 设置的环境变量,存储当前会话 ID。通过检测该变量即可判断是否处于 screen 会话中。