What is Screen
Screen is a tool found only on Linux and highly useful for server configuration and management by a team. It allows users to create, manage, and detach terminal sessions, which can continue running in the background even if the connection to the server is interrupted. Below is a guide for proper use.
Installation
On most Linux distributions,screen comes preinstalled. If not, you can install it with:
Service Installation
Usage
1. Create a new screen session-
To detach a screen, use the combination keys of
CTRL+A+D -
To reattach it, type:
screen -r name -
To see all active sessions, type:
screen -ls
-
Move between screens:
Ctrl + AthenN(next) orP(previous) -
Close the current screen: Type
exit -
Switch to a specific screen within a session:
Ctrl + Afollowed by the window number, e.g.,Ctrl + A 0
- Save the session output:
- Reattach a specific detached session:
- Terminate a specific session:
To forcefully stop a screen, use
screen -X -S session_name kill- End the session using the PID:
-
Get the PID of the session from the screen list, via
screen -ls - Then, type:
- Kill all sessions forcefully:
When to use killall screen: This command should be used as a last resort, as it will terminate all active and detached screen sessions for all users on the system. It’s best used when screens are unresponsive or left open by mistake, especially if you have administrative rights and need to close lingering sessions.