Help Center
Manage screen session
Screen is a command-line tool in Linux that allows you to manage multiple persistent terminal sessions. With screen, you can run programs in the background, detach from a session without closing it, and resume it later.
This is particularly useful for long-running or remote tasks, as your processes continue running even if you disconnect from the server. Additionally, it lets you split the screen, create multiple windows, and efficiently manage your sessions.
You can also combine the use of screen with sending emails via SSH.
To start a new screen session, simply type:
screen
This will start a new session and bring you to a shell within screen.
Create a named session
It's useful to assign a name to the session to identify it more easily:
screen -S session_name
Detaching from a session
To detach from a screen session without closing it (i.e., leave it running in the background), press:
Ctrl + a + d
This will bring you back to the original shell, and the screen session will continue running in the background.
Listing active screen sessions
To view all currently running screen sessions:
screen -ls
The output will be something like:
There is a screen on:
1234.my_long_process
(Detached)
1 Socket in /var/run/screen/S-user.
Resuming a screen session
To resume a detached session:
- If the session is named:
screen -r session_name
- If the session is unnamed or there are multiple sessions:
First, list the sessions withscreen -ls
and then resume using the session ID:screen -r 1234
Terminating a screen session
To end a screen session, you can do so in several ways:
From inside the session
- Exit the shell: Simply type
exit
or pressCtrl + d
to close the shell within screen. This will terminate the session.
From outside the session
- Kill the session by name:
screen -S session_name -X quit
- Kill the session by ID:
screen -X -S 1234 quit
Useful commands within screen
While inside a screen session, you can use various commands. All commands start with Ctrl + a
followed by another key.
- Detach the session:
Ctrl + a + d
- View the screen command list:
Ctrl + a
?
- Create a new window within screen:
Ctrl + a
c
- Switch between windows:
Ctrl + a
n
(next) orp
(previous) - Close the current window:
Ctrl + a
k
Advanced use of screen
Splitting the screen
You can split the screen to view multiple windows at the same time.
- Split horizontally:
Ctrl + a
thenS
- Split vertically:
Ctrl + a
then|
- Move between regions:
Ctrl + a
thenTab
- Close the current region:
Ctrl + a
thenX
Scrollback
To scroll up and view the history:
Ctrl + a
then [
You can then navigate using the arrow keys or Page Up
and Page Down
. To exit scroll mode, press Esc
.
Additional tips
- Custom configuration: You can customize the behavior of screen by editing the
~/.screenrc
file. - Session logging: To log everything happening in a screen session, you can start recording with:
Ctrl + a
thenH
This will create a
screenlog.0
file in the current directory.
The screen tool is extremely powerful and flexible for managing persistent terminal sessions on Linux. With this tutorial, you should be able to create, resume, and terminate screen sessions, as well as use some of its advanced features to improve your workflow.
Related articles
- Screen command in CentOs: more efficient sessions
- Solution: 'Service Unavailable' on CloudLinux servers
- Database export via command line
- Protect your data: configure RAID notifications with S.M.A.R.T.
- List CronJobs for all cPanel users
- Delete unnecessary files from the /tmp partition
- Change reserved disk space in CentOS
- Know your hardware: get accurate information on CentOS 7
- Basic SSH commands
- Optimize accounts with manual rearrange
- IP blocking in CSF via command line
- Clear DNS cache: solution to resolution problems
- Change file permissions via command line
- How to open and close ports using CSF in WHM?
- How to Modify the Hosts File in Windows, Linux, and macOS
- How to Use Telnet to Test SMTP Connectivity on Port 25
- Adjusting reserved space on Linux disks
- Adjusting reconstruction speed in RAID on Linux
- Where are NGINX logs stored?
- Configuring RAID failure notifications with mdadm
- Differences between Legacy VPS and Cloud VPS
- Install cPanel in your server or VPS
- How to send emails via SSH?