âšď¸ Skipped - page is already crawled
| Filter | Status | Condition | Details |
|---|---|---|---|
| HTTP status | PASS | download_http_code = 200 | HTTP 200 |
| Age cutoff | PASS | download_stamp > now() - 6 MONTH | 0 months ago |
| History drop | PASS | isNull(history_drop_reason) | No drop reason |
| Spam/ban | PASS | fh_dont_index != 1 AND ml_spam_score = 0 | ml_spam_score=0 |
| Canonical | PASS | meta_canonical IS NULL OR = '' OR = src_unparsed | Not set |
| Property | Value |
|---|---|
| URL | https://ostechnix.com/screen-command-examples-to-manage-multiple-terminal-sessions/ |
| Last Crawled | 2026-04-08 20:13:41 (17 minutes ago) |
| First Indexed | 2020-07-25 01:02:09 (5 years ago) |
| HTTP Status Code | 200 |
| Meta Title | Screen Command Examples To Manage Multiple Terminal Sessions |
| Meta Description | This guide explains what is GNU Screen and the basic usage of Screen command with examples in Linux and Unix operating systems. |
| Meta Canonical | null |
| Boilerpipe Text | In this guide, we will see what is GNU Screen and the basic usage of Screen command with examples in Linux and Unix operating systems.
Table of Contents
What is GNU Screen?
Install GNU Screen in Linux
Screen Command Examples
Create new Screen session
Detach from Screen sessions
Create a named session
Create detached sessions
List Screen sessions
Attach to Screen sessions
Create nested sessions
Lock sessions
Logging sessions
Autostart Screen sessions
Check If you are an a Screen session or not
Kill Screen sessions
What is GNU Screen?
GNU Screen
is a terminal multiplexer (window manager). As the name says, Screen multiplexes the physical terminal between multiple interactive shells, so we can perform different tasks in each terminal session.
All screen sessions run their programs completely independent. So, a program or process running inside a screen session will keep running even if the session is accidentally closed or disconnected.
For instance, when
upgrading Ubuntu
server via SSH, Screen command will keep running the upgrade process just in case your SSH session is terminated for any reason.
The GNU Screen allows us to easily create multiple screen sessions, switch between different sessions, copy text between sessions, attach or detach from a session at any time and so on.
GNU Screen is one of the important command line tool every Linux admins should learn and use wherever necessary.
Let us see how to manage multiple Terminal sessions using Screen command with examples in Linux.
Install GNU Screen in Linux
GNU Screen is available in the default repositories of most Linux operating systems.
To install GNU Screen on Arch Linux, EndeavourOS, Manjaro Linux, run:
$ sudo pacman -S screen
On Debian, Ubuntu, Linux Mint:
$ sudo apt-get install screen
On Fedora, RHEL, CentOS. AlmaLinux, Rocky Linux:
$ sudo dnf install screen
Or,
$ sudo yum install screen
On CentOS 8, Screen is not available in the official repositories. So you need to enable
[EPEL]
repository and then install screen.
$ sudo dnf install epel-release
$ sudo dnf install screen
On SUSE/openSUSE:
$ sudo zypper install screen
Let us go ahead and see some screen command examples.
Screen Command Examples
The default prefix shortcut to all commands in Screen is
Ctrl+a
. You need to use this shortcut a lot when using Screen. So, just remember this keyboard shortcut.
Create new Screen session
Let us create a new Screen session and attach to it. To do so, type the following command in terminal:
screen
Now, run any program or process inside this session. The running process or program will keep running even if you're disconnected from this session.
Detach from Screen sessions
To detach from inside a screen session, press
Ctrl+a
and
d
. You don't have to press the both key combinations at the same time. First press
Ctrl+a
and then press
d
. After detaching from a session, you will see an output something like below.
[detached from 29149.pts-0.sk]
Here,
29149
is the
screen ID
and
pts-0.sk
is the name of the screen session. You can attach, detach and kill Screen sessions using either screen ID or name of the respective session.
Create a named session
You can also create a screen session with any custom name of your choice other than the default username like below.
screen -S ostechnix
The above command will create a new screen session with name
"xxxxx.ostechnix"
and attach to it immediately. To detach from the current session, press
Ctrl+a
followed by
d
.
Naming screen sessions can be helpful when you want to find which processes are running on which sessions. For example, when a setup LAMP stack inside a session, you can simply name it like below.
screen -S lampstack
Create detached sessions
Sometimes, you might want to create a session, but don't want to attach it automatically. In such cases, run the following command to create detached session named
"senthil"
:
screen -S senthil -d -m
Or, shortly:
screen -dmS senthil
The above command will create a session called "senthil", but won't attach to it.
List Screen sessions
To list all running sessions (attached or detached), run:
screen -ls
Sample output:
There are screens on:
29700.senthil (Detached)
29415.ostechnix (Detached)
29149.pts-0.sk (Detached)
3 Sockets in /run/screens/S-sk.
As you can see, I have three running sessions and all are detached.
If there were no running screen sessions, you will an output like below.
No Sockets found in /run/screen/S-sk.
Attach to Screen sessions
If you want to attach to a session at any time, for example
29415.ostechnix
, simply run:
screen -r 29415.ostechnix
Or,
screen -r ostechnix
Or, just use the screen ID:
screen -r 29415
To verify if we are attached to the aforementioned session, simply list the open sessions and check.
screen -ls
Sample output:
There are screens on:
29700.senthil (Detached)
29415.ostechnix (Attached)
29149.pts-0.sk (Detached)
3 Sockets in /run/screens/S-sk.
As you see in the above output, we are currently attached to
29415.ostechnix
session. To exit from the current session, press ctrl+a, d.
Create nested sessions
When we run "screen" command, it will create a single session for us. We can, however, create nested sessions (a session inside a session).
First, create a new session or attach to an opened session. I am going to create a new session named "nested".
screen -S nested
Now, press
Ctrl+a
and
c
inside the session to create another session. Just repeat this to create any number of nested Screen sessions. Each session will be assigned with a number. The number will start from
0
.
You can move to the next session by pressing
Ctrl+n
and move to previous by pressing
Ctrl+p
.
Here is the list of important Keyboard shortcuts to manage nested sessions.
Ctrl+a â
-Â List all sessions
Ctrl+a 0
- Switch to session number 0
Ctrl+a n
- Switch to next session
Ctrl+a p
- Switch to the previous session
Ctrl+a S
- Split current region horizontally into two regions
Ctrl+a l
- Split current region vertically into two regions
Ctrl+a Q
- Close all sessions except the current one
Ctrl+a X
- Close the current session
Ctrl+a \
- Kill all sessions and terminate Screen
Ctrl+a ?
- Show keybindings. To quit this, press ENTER.
Lock sessions
Screen has an option to lock a screen session. To do so, press
Ctrl+a
and
x
. Enter your Linux password to lock the screen.
Screen used by sk <sk> on ubuntuserver.
Password:
Logging sessions
You might want to log everything when you're in a Screen session. To do so, just press
Ctrl+a
and
H
.
Alternatively, you can enable the logging when starting a new session using
-L
parameter.
screen -L
From now on, all activities you've done inside the session will recorded and stored in a file named
screenlog.x
in your $HOME directory. Here,
x
is a number.
You can view the contents of the log file using
cat
command or any text viewer applications.
Log screen sessions
Autostart Screen sessions
Auto-starting Screen sessions will greatly help when running a long running process via SSH. If you lost the network connectivity for any reason, the process will keep running inside the Screen session in the remote system and you can reattach to it when the network comes back online. To know how to autostart a screen on system startup, refer the following link.
How To Autostart Screen Session On Linux When Logging In
Check If you are an a Screen session or not
As you might have noticed, the normal session and Screen session will look exactly same. You won't see any obvious indication whether you are inside the Screen session or normal session. To know whether you are in Screen session or not, follow the steps given in the below link.
How To Check If You Are In Screen Session Or Not In Linux
Kill Screen sessions
If a session is not required anymore, just kill it. To kill a detached session named "senthil":
screen -r senthil -X quit
Or,
screen -X -S senthil quit
Or,
screen -X -S 29415 quit
If there are no open sessions, you will see the following output:
$ screen -ls
No Sockets found in /run/screens/S-sk.
For more details, refer man pages.
$ man screen
There is also a similar command line utility named
"Tmux"
which does the same job as GNU Screen does. To know more about it, refer the following guide.
Tmux Command Examples To Manage Multiple Terminal Sessions
Resource:
GNU Screen home page
sk
Senthilkumar Palani (aka SK) is the Founder and Editor in chief of OSTechNix. He is a Linux/Unix enthusiast and FOSS supporter. He lives in Tamilnadu, India. |
| Markdown | - [Home](https://ostechnix.com/)
- [Open Source](https://ostechnix.com/category/opensource/)
- [Technology](https://ostechnix.com/category/technology/)
- [Linux](https://ostechnix.com/category/linux/)
- [Unix](https://ostechnix.com/category/unix/)
- [Donate](https://ostechnix.com/donate/)
- [Contact Us](https://ostechnix.com/contact-us/)
- [About](https://ostechnix.com/about/)
[](https://ostechnix.com/)
- [Home](https://ostechnix.com/)
- [Backup tools](https://ostechnix.com/category/backup-tools/)
- [Command line utilities](https://ostechnix.com/category/command-line-utilities/)
- [Database](https://ostechnix.com/category/database/)
- [DevOps](https://ostechnix.com/category/devops/)
- [Mobile](https://ostechnix.com/category/mobile/)
- [Programming](https://ostechnix.com/category/programming/)
- [Security](https://ostechnix.com/category/security/)
- [Virtualization](https://ostechnix.com/category/virtualization/)
[Home](https://ostechnix.com/) [GNU Screen](https://ostechnix.com/category/terminal-multiplexers/gnu-screen/)Screen Command Examples To Manage Multiple Terminal Sessions
[GNU Screen](https://ostechnix.com/category/terminal-multiplexers/gnu-screen/)[Command line utilities](https://ostechnix.com/category/command-line-utilities/)[FAQ](https://ostechnix.com/category/faq/)[Linux](https://ostechnix.com/category/linux/)[Linux Administration](https://ostechnix.com/category/linux-administration/)[Linux Basics](https://ostechnix.com/category/linux-basics/)[Linux Commands](https://ostechnix.com/category/linux-commands/)[Terminal multiplexers](https://ostechnix.com/category/terminal-multiplexers/)[Tips and Tricks](https://ostechnix.com/category/tips-and-tricks/)[Unix/Linux Beginners](https://ostechnix.com/category/unixlinux-beginners/)[Utilities](https://ostechnix.com/category/utilities/)
# Screen Command Examples To Manage Multiple Terminal Sessions
By [sk](https://ostechnix.com/author/sk/)
Published: June 6, 2019
Written by [sk](https://ostechnix.com/author/sk/)
**Published:**
June 6, 2019
**Updated:**
June 25, 2021
*18\.3K* views
2 comments 1[Facebook](https://www.facebook.com/sharer/sharer.php?u=https://ostechnix.com/screen-command-examples-to-manage-multiple-terminal-sessions/)[Twitter](https://x.com/intent/tweet?text=Check%20out%20this%20article:%20Screen%20Command%20Examples%20To%20Manage%20Multiple%20Terminal%20Sessions%20-%20https://ostechnix.com/screen-command-examples-to-manage-multiple-terminal-sessions/)[Linkedin](https://www.linkedin.com/shareArticle?mini=true&url=https%3A%2F%2Fostechnix.com%2Fscreen-command-examples-to-manage-multiple-terminal-sessions%2F&title=Screen%20Command%20Examples%20To%20Manage%20Multiple%20Terminal%20Sessions)[Reddit](https://reddit.com/submit?url=https%3A%2F%2Fostechnix.com%2Fscreen-command-examples-to-manage-multiple-terminal-sessions%2F&title=Screen%20Command%20Examples%20To%20Manage%20Multiple%20Terminal%20Sessions)[Whatsapp](https://api.whatsapp.com/send?text=Screen%20Command%20Examples%20To%20Manage%20Multiple%20Terminal%20Sessions%20%0A%0A%20https%3A%2F%2Fostechnix.com%2Fscreen-command-examples-to-manage-multiple-terminal-sessions%2F)[Telegram](https://telegram.me/share/url?url=https%3A%2F%2Fostechnix.com%2Fscreen-command-examples-to-manage-multiple-terminal-sessions%2F&text=Screen%20Command%20Examples%20To%20Manage%20Multiple%20Terminal%20Sessions)[Email](mailto:?subject=Screen%20Command%20Examples%20To%20Manage%20Multiple%20Terminal%20Sessions&BODY=https://ostechnix.com/screen-command-examples-to-manage-multiple-terminal-sessions/)
*18\.3K*
In this guide, we will see what is GNU Screen and the basic usage of Screen command with examples in Linux and Unix operating systems.
Table of Contents
- [What is GNU Screen?](https://ostechnix.com/screen-command-examples-to-manage-multiple-terminal-sessions/#What_is_GNU_Screen "What is GNU Screen?")
- [Install GNU Screen in Linux](https://ostechnix.com/screen-command-examples-to-manage-multiple-terminal-sessions/#Install_GNU_Screen_in_Linux "Install GNU Screen in Linux")
- [Screen Command Examples](https://ostechnix.com/screen-command-examples-to-manage-multiple-terminal-sessions/#Screen_Command_Examples "Screen Command Examples")
- [Create new Screen session](https://ostechnix.com/screen-command-examples-to-manage-multiple-terminal-sessions/#Create_new_Screen_session "Create new Screen session")
- [Detach from Screen sessions](https://ostechnix.com/screen-command-examples-to-manage-multiple-terminal-sessions/#Detach_from_Screen_sessions "Detach from Screen sessions")
- [Create a named session](https://ostechnix.com/screen-command-examples-to-manage-multiple-terminal-sessions/#Create_a_named_session "Create a named session")
- [Create detached sessions](https://ostechnix.com/screen-command-examples-to-manage-multiple-terminal-sessions/#Create_detached_sessions "Create detached sessions")
- [List Screen sessions](https://ostechnix.com/screen-command-examples-to-manage-multiple-terminal-sessions/#List_Screen_sessions "List Screen sessions")
- [Attach to Screen sessions](https://ostechnix.com/screen-command-examples-to-manage-multiple-terminal-sessions/#Attach_to_Screen_sessions "Attach to Screen sessions")
- [Create nested sessions](https://ostechnix.com/screen-command-examples-to-manage-multiple-terminal-sessions/#Create_nested_sessions "Create nested sessions")
- [Lock sessions](https://ostechnix.com/screen-command-examples-to-manage-multiple-terminal-sessions/#Lock_sessions "Lock sessions")
- [Logging sessions](https://ostechnix.com/screen-command-examples-to-manage-multiple-terminal-sessions/#Logging_sessions "Logging sessions")
- [Autostart Screen sessions](https://ostechnix.com/screen-command-examples-to-manage-multiple-terminal-sessions/#Autostart_Screen_sessions "Autostart Screen sessions")
- [Check If you are an a Screen session or not](https://ostechnix.com/screen-command-examples-to-manage-multiple-terminal-sessions/#Check_If_you_are_an_a_Screen_session_or_not "Check If you are an a Screen session or not")
- [Kill Screen sessions](https://ostechnix.com/screen-command-examples-to-manage-multiple-terminal-sessions/#Kill_Screen_sessions "Kill Screen sessions")
## What is GNU Screen?
**GNU Screen** is a terminal multiplexer (window manager). As the name says, Screen multiplexes the physical terminal between multiple interactive shells, so we can perform different tasks in each terminal session.
All screen sessions run their programs completely independent. So, a program or process running inside a screen session will keep running even if the session is accidentally closed or disconnected.
For instance, when [**upgrading Ubuntu**](https://ostechnix.com/how-to-upgrade-to-ubuntu-18-04-lts-desktop-and-server/) server via SSH, Screen command will keep running the upgrade process just in case your SSH session is terminated for any reason.
The GNU Screen allows us to easily create multiple screen sessions, switch between different sessions, copy text between sessions, attach or detach from a session at any time and so on.
GNU Screen is one of the important command line tool every Linux admins should learn and use wherever necessary.
Let us see how to manage multiple Terminal sessions using Screen command with examples in Linux.
## Install GNU Screen in Linux
GNU Screen is available in the default repositories of most Linux operating systems.
To install GNU Screen on Arch Linux, EndeavourOS, Manjaro Linux, run:
```
$ sudo pacman -S screen
```
On Debian, Ubuntu, Linux Mint:
```
$ sudo apt-get install screen
```
On Fedora, RHEL, CentOS. AlmaLinux, Rocky Linux:
```
$ sudo dnf install screen
```
Or,
```
$ sudo yum install screen
```
On CentOS 8, Screen is not available in the official repositories. So you need to enable **`[EPEL]`** repository and then install screen.
```
$ sudo dnf install epel-release
```
```
$ sudo dnf install screen
```
On SUSE/openSUSE:
```
$ sudo zypper install screen
```
Let us go ahead and see some screen command examples.
## Screen Command Examples
The default prefix shortcut to all commands in Screen is **`Ctrl+a`**. You need to use this shortcut a lot when using Screen. So, just remember this keyboard shortcut.
### Create new Screen session
Let us create a new Screen session and attach to it. To do so, type the following command in terminal:
```
screen
```
Now, run any program or process inside this session. The running process or program will keep running even if you're disconnected from this session.
### Detach from Screen sessions
To detach from inside a screen session, press **Ctrl+a** and **d**. You don't have to press the both key combinations at the same time. First press **Ctrl+a** and then press **d**. After detaching from a session, you will see an output something like below.
```
[detached from 29149.pts-0.sk]
```
Here, **29149** is the **screen ID** and **pts-0.sk** is the name of the screen session. You can attach, detach and kill Screen sessions using either screen ID or name of the respective session.
### Create a named session
You can also create a screen session with any custom name of your choice other than the default username like below.
```
screen -S ostechnix
```
The above command will create a new screen session with name **"xxxxx.ostechnix"** and attach to it immediately. To detach from the current session, press **Ctrl+a** followed by **d**.
Naming screen sessions can be helpful when you want to find which processes are running on which sessions. For example, when a setup LAMP stack inside a session, you can simply name it like below.
```
screen -S lampstack
```
### Create detached sessions
Sometimes, you might want to create a session, but don't want to attach it automatically. In such cases, run the following command to create detached session named **"senthil"**:
```
screen -S senthil -d -m
```
Or, shortly:
```
screen -dmS senthil
```
The above command will create a session called "senthil", but won't attach to it.
### List Screen sessions
To list all running sessions (attached or detached), run:
```
screen -ls
```
Sample output:
```
There are screens on:
29700.senthil (Detached)
29415.ostechnix (Detached)
29149.pts-0.sk (Detached)
3 Sockets in /run/screens/S-sk.
```
As you can see, I have three running sessions and all are detached.
If there were no running screen sessions, you will an output like below.
```
No Sockets found in /run/screen/S-sk.
```
### Attach to Screen sessions
If you want to attach to a session at any time, for example **29415\.ostechnix**, simply run:
```
screen -r 29415.ostechnix
```
Or,
```
screen -r ostechnix
```
Or, just use the screen ID:
```
screen -r 29415
```
To verify if we are attached to the aforementioned session, simply list the open sessions and check.
```
screen -ls
```
Sample output:
```
There are screens on:
29700.senthil (Detached)
29415.ostechnix (Attached)
29149.pts-0.sk (Detached)
3 Sockets in /run/screens/S-sk.
```
As you see in the above output, we are currently attached to **29415\.ostechnix** session. To exit from the current session, press ctrl+a, d.
### Create nested sessions
When we run "screen" command, it will create a single session for us. We can, however, create nested sessions (a session inside a session).
First, create a new session or attach to an opened session. I am going to create a new session named "nested".
```
screen -S nested
```
Now, press **Ctrl+a** and **c** inside the session to create another session. Just repeat this to create any number of nested Screen sessions. Each session will be assigned with a number. The number will start from **0**.
You can move to the next session by pressing **Ctrl+n** and move to previous by pressing **Ctrl+p**.
Here is the list of important Keyboard shortcuts to manage nested sessions.
- **Ctrl+a â** - List all sessions
- **Ctrl+a 0** - Switch to session number 0
- **Ctrl+a n** - Switch to next session
- **Ctrl+a p** - Switch to the previous session
- **Ctrl+a S** - Split current region horizontally into two regions
- **Ctrl+a l** - Split current region vertically into two regions
- **Ctrl+a Q** - Close all sessions except the current one
- **Ctrl+a X** - Close the current session
- **Ctrl+a \\** - Kill all sessions and terminate Screen
- **Ctrl+a ?** - Show keybindings. To quit this, press ENTER.
### Lock sessions
Screen has an option to lock a screen session. To do so, press **Ctrl+a** and **x**. Enter your Linux password to lock the screen.
```
Screen used by sk <sk> on ubuntuserver.
Password:
```
### Logging sessions
You might want to log everything when you're in a Screen session. To do so, just press **Ctrl+a** and **H**.
Alternatively, you can enable the logging when starting a new session using **\-L** parameter.
```
screen -L
```
From now on, all activities you've done inside the session will recorded and stored in a file named **screenlog.x** in your \$HOME directory. Here, **x** is a number.
You can view the contents of the log file using **cat** command or any text viewer applications.
[](https://ostechnix.com/wp-content/uploads/2019/06/Log-screen-sessions.png)
Log screen sessions
**Suggested read:**
- [**How To Record Everything You Do In Terminal**](https://ostechnix.com/record-everything-terminal/)
### Autostart Screen sessions
Auto-starting Screen sessions will greatly help when running a long running process via SSH. If you lost the network connectivity for any reason, the process will keep running inside the Screen session in the remote system and you can reattach to it when the network comes back online. To know how to autostart a screen on system startup, refer the following link.
- [**How To Autostart Screen Session On Linux When Logging In**](https://ostechnix.com/how-to-autostart-screen-session-on-linux-when-logging-in/)
### Check If you are an a Screen session or not
As you might have noticed, the normal session and Screen session will look exactly same. You won't see any obvious indication whether you are inside the Screen session or normal session. To know whether you are in Screen session or not, follow the steps given in the below link.
- [**How To Check If You Are In Screen Session Or Not In Linux**](https://ostechnix.com/how-to-check-if-you-are-in-screen-session-or-not-in-linux/)
### Kill Screen sessions
If a session is not required anymore, just kill it. To kill a detached session named "senthil":
```
screen -r senthil -X quit
```
Or,
```
screen -X -S senthil quit
```
Or,
```
screen -X -S 29415 quit
```
If there are no open sessions, you will see the following output:
```
$ screen -ls
No Sockets found in /run/screens/S-sk.
```
For more details, refer man pages.
```
$ man screen
```
There is also a similar command line utility named **"Tmux"** which does the same job as GNU Screen does. To know more about it, refer the following guide.
- [**Tmux Command Examples To Manage Multiple Terminal Sessions**](https://ostechnix.com/tmux-command-examples-to-manage-multiple-terminal-sessions/)
**Resource:**
- [**GNU Screen home page**](https://www.gnu.org/software/screen/)
[CLI](https://ostechnix.com/tag/cli/)[Linux](https://ostechnix.com/tag/linux/)[Linux commands](https://ostechnix.com/tag/linux-commands/)[Manage Terminal sessions](https://ostechnix.com/tag/manage-terminal-sessions/)[Screen](https://ostechnix.com/tag/screen/)[Screen command examples](https://ostechnix.com/tag/screen-command-examples/)[Screen command usage](https://ostechnix.com/tag/screen-command-usage/)[Terminal](https://ostechnix.com/tag/terminal/)
2 comments 1 [Facebook](https://www.facebook.com/sharer/sharer.php?u=https://ostechnix.com/screen-command-examples-to-manage-multiple-terminal-sessions/)[Twitter](https://x.com/intent/tweet?text=Check%20out%20this%20article:%20Screen%20Command%20Examples%20To%20Manage%20Multiple%20Terminal%20Sessions%20-%20https://ostechnix.com/screen-command-examples-to-manage-multiple-terminal-sessions/)[Linkedin](https://www.linkedin.com/shareArticle?mini=true&url=https%3A%2F%2Fostechnix.com%2Fscreen-command-examples-to-manage-multiple-terminal-sessions%2F&title=Screen%20Command%20Examples%20To%20Manage%20Multiple%20Terminal%20Sessions)[Reddit](https://reddit.com/submit?url=https%3A%2F%2Fostechnix.com%2Fscreen-command-examples-to-manage-multiple-terminal-sessions%2F&title=Screen%20Command%20Examples%20To%20Manage%20Multiple%20Terminal%20Sessions)[Whatsapp](https://api.whatsapp.com/send?text=Screen%20Command%20Examples%20To%20Manage%20Multiple%20Terminal%20Sessions%20%0A%0A%20https%3A%2F%2Fostechnix.com%2Fscreen-command-examples-to-manage-multiple-terminal-sessions%2F)[Telegram](https://telegram.me/share/url?url=https%3A%2F%2Fostechnix.com%2Fscreen-command-examples-to-manage-multiple-terminal-sessions%2F&text=Screen%20Command%20Examples%20To%20Manage%20Multiple%20Terminal%20Sessions)[Email](mailto:?subject=Screen%20Command%20Examples%20To%20Manage%20Multiple%20Terminal%20Sessions&BODY=https://ostechnix.com/screen-command-examples-to-manage-multiple-terminal-sessions/)

##### [sk](https://ostechnix.com/author/sk/ "Author sk")
Senthilkumar Palani (aka SK) is the Founder and Editor in chief of OSTechNix. He is a Linux/Unix enthusiast and FOSS supporter. He lives in Tamilnadu, India.
Previous post
[Welcoming Blockchain 3.0](https://ostechnix.com/welcoming-blockchain-3-0/)
Next post
[How To Find Linux System Details Using inxi](https://ostechnix.com/how-to-find-your-system-details-using-inxi/)
#### You May Also Like
### [GNU Screen 5.0.1 Released With Fixes For Multiple...](https://ostechnix.com/gnu-screen-5-0-1-released/)
Published: May 13, 2025
### [How Tmux Saved My Work and Why You...](https://ostechnix.com/use-tmux-unstable-ssh/)
Published: May 6, 2025
### [Reptyr: Move a Running Process from One Terminal...](https://ostechnix.com/reptyr-move-running-process-new-terminal/)
Published: March 18, 2026
### [How To Zoom Tmux Panes For Better Text...](https://ostechnix.com/how-to-zoom-tmux-panes-for-better-text-visibility/)
Published: February 15, 2020
### [How To Autostart Screen Session On Linux When...](https://ostechnix.com/how-to-autostart-screen-session-on-linux-when-logging-in/)
Published: February 21, 2020
### [How To Check If You Are In Screen...](https://ostechnix.com/how-to-check-if-you-are-in-screen-session-or-not-in-linux/)
Published: February 22, 2020
#### 2 comments

[Ross Brunson](http://www.linuxacademy.com/) July 10, 2020 - 1:43 am
Hi, this is a really nicely done article, comprehensive and helpful.
Thereâs a small item to notify you about, you use the phrase ânested sessionsâ when what you probably mean is âwindows.â
Totally not trying to be a jerk, just wanted to let you know that just about everything you have in that section only needs to say âwindowâ or âwindowsâ instead of âsessionâ or âsessionsâ.
A nested session, which is not really called that, is when you are in a session, such as level1a and you use âscreen -m -S level2aâ to run another session from inside that one.
Unlike a session that has been created from the originating shell, sessions created inside another session have an odd relationship with the parent shell, and are dependent on it.
You might even have issues connecting to the sub-shell, and have to use âscreen -Dr sessionnameâ to properly reattach to it.
Again, nice article, just being helpful\!
[Reply](https://ostechnix.com/screen-command-examples-to-manage-multiple-terminal-sessions/#comment-79714)

[sk](https://ostechnix.com/) July 11, 2020 - 6:23 pm
Thanks for pointing it out, Ross Brunson. I will update this guide with your inputs soon.
[Reply](https://ostechnix.com/screen-command-examples-to-manage-multiple-terminal-sessions/#comment-79761)
### Leave a Comment [Cancel Reply](https://ostechnix.com/screen-command-examples-to-manage-multiple-terminal-sessions/#respond)
This site uses Akismet to reduce spam. [Learn how your comment data is processed.](https://akismet.com/privacy/)
### Search
### Keep in touch
[Facebook](https://www.facebook.com/ostechnix/) [Twitter](https://twitter.com/ostechnix) [Linkedin](https://in.linkedin.com/in/ostechnix) [Youtube](https://www.youtube.com/channel/UC4GsixqwFwsy95oKhpKIS9g) [Email](mailto:info@ostechnix.com) [Reddit](https://www.reddit.com/r/OSTechNix/) [Rss](https://ostechnix.com/feed/)
#### About OSTechNix
[](https://ostechnix.com/)
OSTechNix (Open Source, Technology, Nix\*) regularly publishes the latest news, how-to articles, tutorials and tips & tricks about free and opensource software and technology.
[Facebook](https://www.facebook.com/ostechnix/) [Twitter](https://twitter.com/ostechnix) [Linkedin](https://in.linkedin.com/in/ostechnix) [Youtube](https://www.youtube.com/channel/UC4GsixqwFwsy95oKhpKIS9g) [Email](mailto:info@ostechnix.com) [Reddit](https://www.reddit.com/r/OSTechNix/) [Rss](https://ostechnix.com/feed/)
Archives
#### Popular Posts
- 1
#### [Yt-dlp Commands: The Complete Tutorial For Beginners (2026)](https://ostechnix.com/yt-dlp-tutorial/ "Yt-dlp Commands: The Complete Tutorial For Beginners (2026)")
Published: September 30, 2023
- 2
#### [How To Fix Busybox Initramfs Error On Ubuntu](https://ostechnix.com/how-to-fix-busybox-initramfs-error-on-ubuntu/ "How To Fix Busybox Initramfs Error On Ubuntu")
Published: August 6, 2020
- 3
#### [How to Upgrade to Fedora 44 Beta From Fedora 43 Step-by-Step](https://ostechnix.com/upgrade-to-fedora-44-from-fedora-43/ "How to Upgrade to Fedora 44 Beta From Fedora 43 Step-by-Step")
Published: March 11, 2026
- [About](https://ostechnix.com/about/ "About Us")
- [Contact Us](https://ostechnix.com/contact-us/)
- [Privacy Policy](https://ostechnix.com/privacy-policy/)
- [Sitemap](https://ostechnix.com/sitemap/)
- [Terms and Conditions](https://ostechnix.com/terms-and-conditions/)
OSTechNix Š 2025. All Rights Reserved. This site is licensed under [CC BY-NC 4.0](https://creativecommons.org/licenses/by-nc/4.0/).
[](https://ostechnix.com/)
- [Home](https://ostechnix.com/)
- [Open Source](https://ostechnix.com/category/opensource/)
- [Technology](https://ostechnix.com/category/technology/)
- [Linux](https://ostechnix.com/category/linux/)
- [Unix](https://ostechnix.com/category/unix/)
- [Donate](https://ostechnix.com/donate/)
- [Contact Us](https://ostechnix.com/contact-us/)
- [About](https://ostechnix.com/about/)
This website uses cookies to improve your experience. By using this site, we will assume that you're OK with it. [Accept](https://ostechnix.com/screen-command-examples-to-manage-multiple-terminal-sessions/) [Read More](https://ostechnix.com/terms-and-conditions/) |
| Readable Markdown | In this guide, we will see what is GNU Screen and the basic usage of Screen command with examples in Linux and Unix operating systems.
Table of Contents
- [What is GNU Screen?](https://ostechnix.com/screen-command-examples-to-manage-multiple-terminal-sessions/#What_is_GNU_Screen "What is GNU Screen?")
- [Install GNU Screen in Linux](https://ostechnix.com/screen-command-examples-to-manage-multiple-terminal-sessions/#Install_GNU_Screen_in_Linux "Install GNU Screen in Linux")
- [Screen Command Examples](https://ostechnix.com/screen-command-examples-to-manage-multiple-terminal-sessions/#Screen_Command_Examples "Screen Command Examples")
- [Create new Screen session](https://ostechnix.com/screen-command-examples-to-manage-multiple-terminal-sessions/#Create_new_Screen_session "Create new Screen session")
- [Detach from Screen sessions](https://ostechnix.com/screen-command-examples-to-manage-multiple-terminal-sessions/#Detach_from_Screen_sessions "Detach from Screen sessions")
- [Create a named session](https://ostechnix.com/screen-command-examples-to-manage-multiple-terminal-sessions/#Create_a_named_session "Create a named session")
- [Create detached sessions](https://ostechnix.com/screen-command-examples-to-manage-multiple-terminal-sessions/#Create_detached_sessions "Create detached sessions")
- [List Screen sessions](https://ostechnix.com/screen-command-examples-to-manage-multiple-terminal-sessions/#List_Screen_sessions "List Screen sessions")
- [Attach to Screen sessions](https://ostechnix.com/screen-command-examples-to-manage-multiple-terminal-sessions/#Attach_to_Screen_sessions "Attach to Screen sessions")
- [Create nested sessions](https://ostechnix.com/screen-command-examples-to-manage-multiple-terminal-sessions/#Create_nested_sessions "Create nested sessions")
- [Lock sessions](https://ostechnix.com/screen-command-examples-to-manage-multiple-terminal-sessions/#Lock_sessions "Lock sessions")
- [Logging sessions](https://ostechnix.com/screen-command-examples-to-manage-multiple-terminal-sessions/#Logging_sessions "Logging sessions")
- [Autostart Screen sessions](https://ostechnix.com/screen-command-examples-to-manage-multiple-terminal-sessions/#Autostart_Screen_sessions "Autostart Screen sessions")
- [Check If you are an a Screen session or not](https://ostechnix.com/screen-command-examples-to-manage-multiple-terminal-sessions/#Check_If_you_are_an_a_Screen_session_or_not "Check If you are an a Screen session or not")
- [Kill Screen sessions](https://ostechnix.com/screen-command-examples-to-manage-multiple-terminal-sessions/#Kill_Screen_sessions "Kill Screen sessions")
## What is GNU Screen?
**GNU Screen** is a terminal multiplexer (window manager). As the name says, Screen multiplexes the physical terminal between multiple interactive shells, so we can perform different tasks in each terminal session.
All screen sessions run their programs completely independent. So, a program or process running inside a screen session will keep running even if the session is accidentally closed or disconnected.
For instance, when [**upgrading Ubuntu**](https://ostechnix.com/how-to-upgrade-to-ubuntu-18-04-lts-desktop-and-server/) server via SSH, Screen command will keep running the upgrade process just in case your SSH session is terminated for any reason.
The GNU Screen allows us to easily create multiple screen sessions, switch between different sessions, copy text between sessions, attach or detach from a session at any time and so on.
GNU Screen is one of the important command line tool every Linux admins should learn and use wherever necessary.
Let us see how to manage multiple Terminal sessions using Screen command with examples in Linux.
## Install GNU Screen in Linux
GNU Screen is available in the default repositories of most Linux operating systems.
To install GNU Screen on Arch Linux, EndeavourOS, Manjaro Linux, run:
```
$ sudo pacman -S screen
```
On Debian, Ubuntu, Linux Mint:
```
$ sudo apt-get install screen
```
On Fedora, RHEL, CentOS. AlmaLinux, Rocky Linux:
```
$ sudo dnf install screen
```
Or,
```
$ sudo yum install screen
```
On CentOS 8, Screen is not available in the official repositories. So you need to enable **`[EPEL]`** repository and then install screen.
```
$ sudo dnf install epel-release
```
```
$ sudo dnf install screen
```
On SUSE/openSUSE:
```
$ sudo zypper install screen
```
Let us go ahead and see some screen command examples.
## Screen Command Examples
The default prefix shortcut to all commands in Screen is **`Ctrl+a`**. You need to use this shortcut a lot when using Screen. So, just remember this keyboard shortcut.
### Create new Screen session
Let us create a new Screen session and attach to it. To do so, type the following command in terminal:
```
screen
```
Now, run any program or process inside this session. The running process or program will keep running even if you're disconnected from this session.
### Detach from Screen sessions
To detach from inside a screen session, press **Ctrl+a** and **d**. You don't have to press the both key combinations at the same time. First press **Ctrl+a** and then press **d**. After detaching from a session, you will see an output something like below.
```
[detached from 29149.pts-0.sk]
```
Here, **29149** is the **screen ID** and **pts-0.sk** is the name of the screen session. You can attach, detach and kill Screen sessions using either screen ID or name of the respective session.
### Create a named session
You can also create a screen session with any custom name of your choice other than the default username like below.
```
screen -S ostechnix
```
The above command will create a new screen session with name **"xxxxx.ostechnix"** and attach to it immediately. To detach from the current session, press **Ctrl+a** followed by **d**.
Naming screen sessions can be helpful when you want to find which processes are running on which sessions. For example, when a setup LAMP stack inside a session, you can simply name it like below.
```
screen -S lampstack
```
### Create detached sessions
Sometimes, you might want to create a session, but don't want to attach it automatically. In such cases, run the following command to create detached session named **"senthil"**:
```
screen -S senthil -d -m
```
Or, shortly:
```
screen -dmS senthil
```
The above command will create a session called "senthil", but won't attach to it.
### List Screen sessions
To list all running sessions (attached or detached), run:
```
screen -ls
```
Sample output:
```
There are screens on:
29700.senthil (Detached)
29415.ostechnix (Detached)
29149.pts-0.sk (Detached)
3 Sockets in /run/screens/S-sk.
```
As you can see, I have three running sessions and all are detached.
If there were no running screen sessions, you will an output like below.
```
No Sockets found in /run/screen/S-sk.
```
### Attach to Screen sessions
If you want to attach to a session at any time, for example **29415\.ostechnix**, simply run:
```
screen -r 29415.ostechnix
```
Or,
```
screen -r ostechnix
```
Or, just use the screen ID:
```
screen -r 29415
```
To verify if we are attached to the aforementioned session, simply list the open sessions and check.
```
screen -ls
```
Sample output:
```
There are screens on:
29700.senthil (Detached)
29415.ostechnix (Attached)
29149.pts-0.sk (Detached)
3 Sockets in /run/screens/S-sk.
```
As you see in the above output, we are currently attached to **29415\.ostechnix** session. To exit from the current session, press ctrl+a, d.
### Create nested sessions
When we run "screen" command, it will create a single session for us. We can, however, create nested sessions (a session inside a session).
First, create a new session or attach to an opened session. I am going to create a new session named "nested".
```
screen -S nested
```
Now, press **Ctrl+a** and **c** inside the session to create another session. Just repeat this to create any number of nested Screen sessions. Each session will be assigned with a number. The number will start from **0**.
You can move to the next session by pressing **Ctrl+n** and move to previous by pressing **Ctrl+p**.
Here is the list of important Keyboard shortcuts to manage nested sessions.
- **Ctrl+a â** - List all sessions
- **Ctrl+a 0** - Switch to session number 0
- **Ctrl+a n** - Switch to next session
- **Ctrl+a p** - Switch to the previous session
- **Ctrl+a S** - Split current region horizontally into two regions
- **Ctrl+a l** - Split current region vertically into two regions
- **Ctrl+a Q** - Close all sessions except the current one
- **Ctrl+a X** - Close the current session
- **Ctrl+a \\** - Kill all sessions and terminate Screen
- **Ctrl+a ?** - Show keybindings. To quit this, press ENTER.
### Lock sessions
Screen has an option to lock a screen session. To do so, press **Ctrl+a** and **x**. Enter your Linux password to lock the screen.
```
Screen used by sk <sk> on ubuntuserver.
Password:
```
### Logging sessions
You might want to log everything when you're in a Screen session. To do so, just press **Ctrl+a** and **H**.
Alternatively, you can enable the logging when starting a new session using **\-L** parameter.
```
screen -L
```
From now on, all activities you've done inside the session will recorded and stored in a file named **screenlog.x** in your \$HOME directory. Here, **x** is a number.
You can view the contents of the log file using **cat** command or any text viewer applications.
[](https://ostechnix.com/wp-content/uploads/2019/06/Log-screen-sessions.png)
Log screen sessions
### Autostart Screen sessions
Auto-starting Screen sessions will greatly help when running a long running process via SSH. If you lost the network connectivity for any reason, the process will keep running inside the Screen session in the remote system and you can reattach to it when the network comes back online. To know how to autostart a screen on system startup, refer the following link.
- [**How To Autostart Screen Session On Linux When Logging In**](https://ostechnix.com/how-to-autostart-screen-session-on-linux-when-logging-in/)
### Check If you are an a Screen session or not
As you might have noticed, the normal session and Screen session will look exactly same. You won't see any obvious indication whether you are inside the Screen session or normal session. To know whether you are in Screen session or not, follow the steps given in the below link.
- [**How To Check If You Are In Screen Session Or Not In Linux**](https://ostechnix.com/how-to-check-if-you-are-in-screen-session-or-not-in-linux/)
### Kill Screen sessions
If a session is not required anymore, just kill it. To kill a detached session named "senthil":
```
screen -r senthil -X quit
```
Or,
```
screen -X -S senthil quit
```
Or,
```
screen -X -S 29415 quit
```
If there are no open sessions, you will see the following output:
```
$ screen -ls
No Sockets found in /run/screens/S-sk.
```
For more details, refer man pages.
```
$ man screen
```
There is also a similar command line utility named **"Tmux"** which does the same job as GNU Screen does. To know more about it, refer the following guide.
- [**Tmux Command Examples To Manage Multiple Terminal Sessions**](https://ostechnix.com/tmux-command-examples-to-manage-multiple-terminal-sessions/)
**Resource:**
- [**GNU Screen home page**](https://www.gnu.org/software/screen/)

##### [sk](https://ostechnix.com/author/sk/ "Author sk")
Senthilkumar Palani (aka SK) is the Founder and Editor in chief of OSTechNix. He is a Linux/Unix enthusiast and FOSS supporter. He lives in Tamilnadu, India. |
| Shard | 40 (laksa) |
| Root Hash | 10538567265436171840 |
| Unparsed URL | com,ostechnix!/screen-command-examples-to-manage-multiple-terminal-sessions/ s443 |