Introduction to Screen Sessions
Screen is a powerful utility in Linux that allows users to create and manage multiple terminal sessions from a single console. It provides features like detaching and reattaching sessions, which makes it ideal for running long-running commands or experiments without being tied to the console.
Listing Running Screen Sessions
To list all running screen sessions, you can use the screen -ls
command. This will display a list of detached screens with their corresponding session IDs.
Example:
$ screen -ls
There are screens on:
12931.pts-0.gentle (Detached)
6764.pts-1.v1091330 (Detached)
2 Sockets in /var/run/screen/S-josh.
In this example, we have two detached screen sessions with IDs 12931.pts-0.gentle
and 6764.pts-1.v1091330
.
Attaching to a Running Screen Session
To attach to a running screen session, you can use the screen -x
command followed by the session ID.
Example:
$ screen -x 12931.pts-0.gentle
This will reattach you to the screen session with the specified ID.
Detaching from a Screen Session
To detach from a screen session without terminating it, press Ctrl + A
followed by D
. This will leave the session running in the background.
Terminating a Screen Session
To terminate a screen session, press Ctrl + D
while attached to the session. Alternatively, you can use the killall screen
command to terminate all running screen sessions.
Tips and Variations
- To create a new screen session, simply type
screen
. - You can set a custom title for your screen session using the
-t
option, e.g.,screen -t mysession
. - To list all screen sessions on a system, including those owned by other users, you can use the
ls -laR /var/run/screen/
command. - If you want to identify a screen session by its name (set with the
-t
option), you can use a script likeps auxw|grep -i screen|grep -v grep
.
Conclusion
In this tutorial, we covered the basics of managing screen sessions on Linux systems. By using the screen -ls
command to list running sessions and the screen -x
command to attach to them, you can easily manage multiple terminal sessions from a single console.