Is there a way to give a particular name to a unix screen session? For instance, say I'm running the same program multiple times, each with different parameters and I want to tell which one is which.
Setting a name for a screen session
gnu-screen
Related Solutions
If I understand correctly, you want to send input to a program running inside a screen session. You can do this with screen's stuff
command. Use screen's -X
option to execute a command in a screen session without attaching to it.
screen -S sessionname -p windowname -X stuff 'command1
command2
'
If you want to see the program's output, see the hardcopy
, log
and logfile
commands.
If there are no other screen
sessions running you can use the "hard" way and just kill
them with killall screen
.
If you want to be nice you can iterate over your list of screen sessions and kill them one after another:
# screen -S foo && screen -S foo
[detached]
[detached]
# screen -ls
There are screens on:
8350.foo (Detached)
8292.foo (Detached)
2 Sockets in /tmp/screens/S-joschi.
# This is the interesting line. Just replace "foo" with the name of your session(s)
# for session in $(screen -ls | grep -o '[0-9]*\.foo'); do screen -S "${session}" -X quit; done
# screen -ls
No Sockets found in /tmp/screens/S-joschi.
Best Answer
You can name a session when starting it with the
-S name
option. From within a running screen, you can change it by typingCtrl+A,: followed by
sessionname name
(1).You can view running screen sessions with
screen -ls
, and connect to one by name with(1):
name
is and an arbitrary string which will become the new session name. If the session name contains whitespace, quote it with single or double quotes.Within a single screen session, you can also name each window. Do this by typing Ctrl+A, A then the name you want. You can view an interactive list of named windows by typing Ctrl+A, ", and select the one you want to switch to from that list.
Naming both screens and terminals within screens is really helpful for remembering what they are and why you started them in the first place.