In screen there is a kill command, which kills the current window. This command can be sent even to a detached screen session by running:

screen -S SessionName -X kill

This works to kill the current window only. To kill any other window, it appears the only way is to first switch to that window and then kill it. The select command allows switching between windows in a screen session. Typing the following while attached to a screen session will select the window named foo.

^A:select foo

However, when not attached to the session, it appears the select command has no effect. Running the following two commands will kill the current window, rather than the window named foo (unless of course that is the active window).

screen -S SessionName -X select foo
screen -S SessionName -X kill

I have verified that this occurs even if I attach and detach from the session before attempting to select a window (a known workaround for some other screen quirks).

  • Did you omit quotes around "select foo"?
    – Celada
    Aug 31 '15 at 3:28
  • I've tried three variations in quoting. None of them work better than the others. "-X select foo" produces an error (expected). -X "select foo" produces no effect. -X select "foo" produces no effect.
    – Huckle
    Aug 31 '15 at 3:31

You can try -p to select the window, numbered from 0, eg

screen -S SessionName -p 1 -X kill
  • 1
    It seems that although the screen man page says that the kill command operates on the current window, it in fact requires the -p flag to select the window by title.
    – Huckle
    Sep 1 '15 at 4:11

Not the answer you're looking for? Browse other questions tagged or ask your own question.