Operations 8 min read

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.

Liangxu Linux
Liangxu Linux
Liangxu Linux
Never Lose Long‑Running Linux Tasks Again: Master the Screen Command

Installation

Many Linux distributions ship screen by default. Verify the installation with:

$ screen --version
Screen version 4.06.02 (GNU) 23-Oct-17

If it is missing, install it using the package manager:

$ sudo apt install screen

Starting 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 alvin

Detaching 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.

Screen detach message
Screen detach message

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 alvin

Nested 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:

$ exit
Screen exit
Screen exit

Best 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.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Linuxcommand-lineterminalscreen
Liangxu Linux
Written by

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.)

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.