Screen 202: Making Screen a Little More User Friendly
By now you’ve learned the basics of using screen from my previous posts. You may be wondering how to keep track of what you have running in each of your screen sessions. With this post we’ll show you how to add a little more context to screen that will allow you to more easily see what you’ve got running.
As discussed in my Screen 101 article, to the list of running screen sessions you can attach you’d type ‘screen -ls’:
[demouser@myserver ~]$ screen -ls There are screens on: 5910.pts-2.myserver (Attached) 7316.pts-0.myserver (Detached) 2 Sockets in /var/run/screen/S-myserver.
Define a Session Name:
The problem is “5910.pts-2.myserver” doesn’t really explain what you’ve got running in that screen session. There are 2 ways to address this depending on if you are just about to start your session or you’re already in it.
First, as you are starting your screen session you can specify a name with the -S (capital S):
[demouser@myserver ~]$ screen -S MySessionName
Or once you are in your screen session you can do ‘C-a :’ (Ctrl-a followed by : ) will get you to screen’s command line prompt. Then you can specify your session’s name with ‘sessionname MySessionName’.
Regardless of which method you use the result will be the same. When you list your screen sessions it will now look like:
[demouser@myserver ~]$ screen -ls There is a screen on: 4540.MySessionName (03/16/2018 10:12:10 AM) (Detached) 1 Socket in /var/run/screen/S-myserver.
You’ll be able to reattach to that session with either the process ID of 4540 or just the name you assigned:
[demouser@myserver ~]$ screen -r MySessionName
Define a Window Title:
Now, you may notice while in your screen session you won’t see that name reflected in your terminal window. You can set this with ‘C-a A’ (Ctrl-a followed by A). You’ll get a prompt like:
Simply backspace to clear ‘bash’ and type whatever you’d like your new title to be:
Detach from a Screen Session:
When you want to exit a screen session while leaving your session running in the background you can simply enter ‘C-a d’ (Ctrl-A followed by d).
So Much More….
Between the 3 posts on screen we’ve barely scratched the surface of how powerful screen is and what you can do with it. Hopefully, I’ve piqued your interest and you’ve been able to play with it enough to find it useful. From here I’d strongly recommend you review the screen man page and this screen quick reference page to continue growing your screen skills.
Do you use screen? Love it? Hate it? Or have another utility you can’t live without? Let me know by leaving a comment!