Linux Commands
When performing tasks in a screen session, the session persists even if the terminal session disconnects, ensuring that your work is not interrupted.
For this reason, screen is commonly used on Linux servers for batch tasks, long-running processes, and background jobs.
While screen can also be used for window splitting, I generally prefer to use tmux for that purpose.
External Session Commands
Action | Command | Description |
---|---|---|
List screen sessions | screen -list screen -ls | Displays a list of open screen sessions, showing whether each session is attached/detached, the creation time, and the session ID. |
Start a screen | screen -S {name} | Creates and enters a new screen session with the specified name .Even if a session with the same name exists, a new session will be created with a different session ID. |
Enter a screen | screen -r {name} or {sessionId} | Re-enters an existing screen session using the name or sessionId .If there are multiple sessions with the same name, the session ID must be specified. |
Enter a screen | screen -x {name} or {sessionId} | Similar to -r when used alone.The -x option allows entry into an attached session (already connected in another terminal).The -r option does not allow this. |
Kill a screen session | screen -X -S {name} kill | Kills a specific session. This is used to terminate a session that was detached without being exited, keeping it alive. |
Kill all screen sessions | killall screen pkill screen | Terminates all screen sessions. Use with caution as it can lead to accidental termination of important sessions. |
Internal Session Commands
Action | Command | Description |
---|---|---|
Detach from screen | ctrl + a d | Detaches from the screen session, leaving it running in the background. This is the most frequently used command. |
Check session ID | echo $STY | Displays the session ID of the current screen session. This command is often used to verify whether the terminal is inside a screen session. |
There are many other commands available, but for window splitting, using tmux is more convenient.