Screen is a terminal multiplexer that allows you to run multiple shell sessions within a single terminal window. Each screen session runs as a separate background process, so commands and scripts continue executing even if the terminal is closed or the SSH connection is lost.
Screen is commonly used for:
- Running long-running commands on remote servers
- Managing multiple shells over SSH
- Preventing accidental termination of critical processes
- Switching between multiple terminal sessions efficiently
screen Command - Quick Cheat Sheet
This quick reference summarizes the most commonly used screen command examples in Linux for managing persistent terminal sessions.
| Task | screen Command |
|---|---|
| Start a new screen session | screen |
| Start a named screen session | screen -S session_name |
| List running screen sessions | screen -ls |
| Reattach to a detached session | screen -r |
| Reattach to a specific session | screen -r session_name |
| Detach from current session | Ctrl + A then D |
| Kill a screen session | screen -X -S session_name quit |
| Create a new window inside screen | Ctrl + A then C |
| Switch to next window | Ctrl + A then N |
| Switch to previous window | Ctrl + A then P |
| Switch to window by number | Ctrl + A then number |
| Rename current window | Ctrl + A then A |
| Split screen horizontally | Ctrl + A then S |
| Move between split regions | Ctrl + A then Tab |
| Close current window | exit |
| Force detach session from another terminal | screen -D -r session_name |
Installing Screen on Linux
Screen is available in the default repositories of most Linux distributions and can be installed using the system package manager.
Install on RHEL / Fedora / Rocky / AlmaLinux
On modern RHEL-based systems:
sudo dnf install screen -yOn older systems:
sudo yum install screen -yInstall on Debian / Ubuntu / Linux Mint
Install screen using APT:
sudo apt install screen -yOn older Debian-based distributions:
sudo apt-get install screen -yInstall on Arch / openSUSE / Gentoo
On Arch Linux:
sudo pacman -S screenOn openSUSE:
sudo zypper install screenOn Gentoo:
sudo emerge -a sys-apps/screenGetting Started with Screen
Once installed, you can start using screen immediately from the terminal. Screen sessions can be exited or detached depending on whether you want the session to continue running.
Start a Screen Session
Start a new screen session by running:
screenThis opens a new shell inside screen. Any command executed in this session will continue running until the session is explicitly closed.
Exit vs Detach a Screen Session
There is an important difference between exiting and detaching a screen session.
To exit and terminate the screen session:
exitThis stops the screen process and all commands running inside it.
To detach the screen session and keep it running in the background:
Ctrl + a + dDetaching allows you to safely disconnect from the terminal while the screen session continues running. You can reattach to it later.
Common Screen Keyboard Shortcuts
Below are some commonly used keyboard shortcuts inside a screen session.
All shortcuts start with Ctrl + a.
| Shortcut | Action |
|---|---|
Ctrl + a ? | Show all key bindings |
Ctrl + a c | Create a new window |
Ctrl + a n | Switch to the next window |
Ctrl + a p | Switch to the previous window |
Ctrl + a w | List all windows |
Ctrl + a " | Select a window from a list |
Ctrl + a d | Detach the current session |
Ctrl + a k | Kill the current window |
Ctrl + a [ | Enter scrollback / copy mode |
Screen Command Quick Reference Table
Commonly used screen commands at a glance:
| Command | Description |
|---|---|
screen | Start a new screen session |
screen -ls | List all screen sessions |
screen -r | Attach to a screen session |
screen -d | Detach a screen session |
screen -d -r | Detach and reattach a session |
screen -S name | Start a named session |
screen -X -S id quit | Kill a screen session |
screen -L | Start a session with logging enabled |
Managing Screen Sessions
List Screen Sessions
To view all currently running screen sessions, use:
screen -lsor
screen -listThis displays the session ID, session name, and whether it is Attached or Detached.
Attach to a Screen Session
To attach to an existing screen session, specify the session ID or name:
screen -r 9074.pts-1.fedoraIf only one detached session exists, you can simply run:
screen -rDetach a Screen Session
To detach from the current screen session without stopping it, use the keyboard shortcut:
Ctrl + a + dThis keeps the session running in the background and returns you to the normal shell.
You can also detach a session from another terminal using:
screen -d 9074.pts-1.fedoraReattach a Detached Session
To reattach a previously detached screen session:
screen -r 9074.pts-1.fedoraIf the session is attached elsewhere and you want to force reattachment:
screen -d -r 9074.pts-1.fedoraClose (Kill) a Screen Session
To terminate a specific screen session, use the following command:
screen -X -S 9074.pts-1.fedora quitThis immediately stops the screen session and any processes running inside it. Use this carefully to avoid terminating important tasks.
Working with Multiple Windows in Screen
A single screen session can contain multiple windows, each running its own shell or command. This allows you to manage several tasks within one screen session without opening multiple terminals.
Create a New Screen Window
To create a new window inside the current screen session, use the keyboard shortcut:
Ctrl + a + cThis opens a new shell window while keeping the previous one running in the background.
Switch Between Screen Windows
You can switch between windows using the following shortcuts:
Ctrl + a + n Switch to the next window
Ctrl + a + p Switch to the previous windowTo display a list of all windows:
Ctrl + a + wTo select a window from an interactive list:
Ctrl + a + "Rename a Screen Window
Renaming windows helps identify what task is running in each window.
To rename the current window:
Ctrl + a + AEnter a descriptive name, such as the service or script running in that window.
You can also set a window name when creating it:
screen -t build-sessionScreen Security and Locking
Screen provides a built-in locking mechanism to prevent unauthorized access to an active session.
Lock a Screen Session
To lock the current screen session, use:
Ctrl + a + xThe session will be locked immediately and prompt for the user password to regain access. This is useful when stepping away from a terminal on a shared or remote system.
Logging and Monitoring
Enable Logging for a Screen Session
To start a screen session with logging enabled, use:
screen -LThis creates a file named screenlog.0 in the directory where the
session was started. All terminal output in that session is written to
this file.
You can also enable logging for an already running session using:
Ctrl + a + HThis toggles logging on or off for the current window.
View Screen Log Files
To view the contents of the screen log file:
cat screenlog.0Or follow the log in real time:
tail -f screenlog.0Log files are plain text and can be archived or shared if needed.
Screen vs tmux (Which Should You Use?)
Both screen and tmux are terminal multiplexers that allow you to run persistent terminal sessions, but they differ in features, development activity, and flexibility.
Use screen when:
- It is already installed on the system
- You are working on minimal or legacy servers
- You need basic session attach/detach functionality
- You want a simple, no-configuration setup
Use tmux when:
- You want split panes and advanced layouts
- You need better scripting and automation support
- You frequently customize key bindings and status bars
- You work heavily with SSH and modern development workflows
In general, tmux is more actively maintained and preferred for new setups, while screen remains a reliable choice for quick access and older environments where tmux may not be available.
Summary
The screen command is a powerful utility for managing persistent
terminal sessions in Linux. It allows you to detach and reattach
sessions, manage multiple windows, enable logging, and secure sessions
with locking.
Screen is especially useful for remote administration, long-running tasks, and environments where tmux may not be available.

![How to Use Screen in Linux [List, Attach, Detach, Close]](/command-screen-linux/screen-command-in-linux-800w.webp)
