Never Lose Long‑Running Linux Tasks Again: Master the Screen Command
This guide explains how to install, start, name, detach, reattach, nest, switch between, and close GNU Screen sessions on Linux, providing concrete commands and key shortcuts to keep long‑running tasks alive even when network connections drop.
Installation
Many Linux distributions ship screen by default. Verify the installation with:
$ screen --version
Screen version 4.06.02 (GNU) 23-Oct-17If it is missing, install it using the package manager:
$ sudo apt install screenStarting a Screen Session
Launch a new session simply by running: $ screen The initial screen shows copyright information; press Enter or Space to continue to a regular terminal.
You can give the session a name for easier identification:
$ screen -S alvinDetaching and Re‑attaching
While a long‑running command (e.g., a system update) is executing, detach the session with Ctrl‑a d. The process continues in the background.
Re‑attach to the most recent session with: $ screen -r If multiple sessions exist, list them: $ screen -ls Then re‑attach by specifying the session ID or name, e.g.:
$ screen -r 4352
$ screen -r alvinNested Sessions
Start a screen inside an existing screen to run parallel tasks. Use the same screen command or the shortcut Ctrl‑a c: $ screen Switch between nested sessions with Ctrl‑a n (next) or Ctrl‑a p (previous).
Closing a Session
Terminate a screen session as you would a normal shell: press Ctrl‑d or type exit:
$ exitBest Practices
Using screen prevents data loss when network connections drop and allows multiple concurrent tasks within a single terminal window. Naming sessions ( -S) simplifies re‑attachment, and detaching ( Ctrl‑a d) keeps long‑running jobs alive without keeping the SSH connection open.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Liangxu Linux
Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
