How to Kill a Specific Screen in GNU Screen

bashgnu-screenkill

I have multiple screens running on an Ubuntu server that are initiated as:

screen -dmS screen1 cmd
screen -dmS screen2 cmd
etc...

And I need to kill one screen, but not all of them. What is the correct command to kill a single particular screen with its name? I've read through the man pages but I can't seem to find the command I am looking for.

Also I want to write this command into a bash script so I can't simply screen -r screen1 then press Ctrl+X as I normally would.

Best Answer

From the man page :

   -X   Send the specified command to a running screen  session.  You  can
        use  the  -d or -r option to tell screen to look only for attached
        or detached screen sessions. Note that this command  doesn't  work
        if the session is password protected.

You can do :

        screen -X -S <sessionid> kill