Our Knowledge Base provides step-by-step guides, troubleshooting tips, and expert insights to help you manage VPS, dedicated servers, domains, DDoS protection, and more — all designed to make your experience with us fast, secure, and stress-free.
At its core, screen is a terminal multiplexer. It enables users to open multiple virtual terminals within a single physical terminal or remotely accessed terminal. With screen, you can start long-running processes, keep them running even if your connection drops, detach from the sessions, and later reattach to them from another location.
In most Linux OS screen are preinstalled. If it’s not installed you need to install manually:
To initiate a new screen session, simply type:
screen
This will create a new virtual terminal, and you can start working as you would in a regular terminal. To exit the session, press Ctrl + A followed by D. This detaches you from the session, allowing it to keep running in the background.
After detaching from a screen session, you can later reattach to it and resume your work. To list all available screen sessions, execute:
screen -ls
The output will display a list of available sessions along with their unique session IDs. To reattach to a specific session, use:
screen -r session_id
By default, screen sessions are identified by session IDs, which can be cumbersome to remember. To make your life easier, you can give meaningful names to your sessions using the -S flag when starting a new session. For example:
screen -S my_session
Now, you can reattach to this session by using its name instead of the session ID:
screen -r my_session
Within a single screen session, you can create and manage multiple terminal windows, each functioning independently. To create a new window, press:
Ctrl + A, C
To switch between different windows, use:
Ctrl + A, N (Next window) Ctrl + A, P (Previous window)
If you want to switch directly to a specific window, press:
Ctrl + A, <number>
To close the current window, type exit. Be cautious as this only closes the window but not the underlying process. The process will continue running in the background.
One of the most useful features of screen is the ability to split the terminal window into multiple regions, displaying different terminal sessions simultaneously. To split the screen vertically, use:
Ctrl + A, |
To split the screen horizontally, use:
Ctrl + A, S
Switch between split screen regions by pressing:
Ctrl + A, Tab
screen also allows you to copy and paste text between different windows within a session. To enter copy mode, press:
Ctrl + A, [
Use the arrow keys or the vi editor keybindings to navigate and select the text. To copy the selected text, press Enter. To paste the copied text, press:
Ctrl + A, ]
To exit a screen session, ensure that all windows within the session are closed. Then, type:
exit
This will terminate the screen session.
The Linux screen command is a powerful tool that enhances terminal multitasking and remote server management. By mastering the various features and shortcuts of screen, you can boost your productivity and efficiently manage multiple terminal sessions. Whether you are a system administrator, developer, or power user, screen is a valuable addition to your Linux toolkit. So, start exploring the capabilities of screen and unlock the true potential of the Linux command line.