My scenario is this:

I have a screen session running in a remote location. Inside this screen is a consoled-based program. When run without screen, this program starts in the terminal and accepts commands on its standard input.

What I want is a way to remotely send a command to screen so that this command is received by the console program. Maybe like this:

My PC -> SSH Send Msg Auto -> Screen Session -> Program (Run command received)

So from a remote PC I can send via SSH commands to the screen which sends them to the program. The program accepts them and executes them.

2 Answers 2


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

If you want to see the program's output, see the hardcopy, log and logfile commands.

  • Already tried the stuff command but it only sends commands that are from screen. You see it accepts only the commands that are screen related, not the program am using related. Jan 1, 2011 at 19:54
  • @CYREX: stuff sends characters, exactly as if you had typed them. What exactly did you try, what was the intended effect, and what happened instead? Jan 1, 2011 at 19:59
  • I see you have the -p part. I did not have that. Added that part and it is sending the command now but how can i press ENTER for each command? Jan 1, 2011 at 20:52
  • Found it. Addint $ before the quotes and having C like escapes in it. Like this -X stuff $'show users\n' Jan 1, 2011 at 20:56
  • @CYREX: -p is necessary (or at least a good idea) if there is more than one window. To “press Enter”, just include a newline in the argument (i.e. inside the quotes), as I've done. Jan 1, 2011 at 21:00

To send a command to a detached screen:

screen -S <screen_name> -X stuff "command blah blah blah\n"
  • Be sure to have "\n" at the end of the command. If you don't append the "\n", then the command will be sent but won't initiate.

Side Note : If you want to leave a screen that you are inside of without ending it, use the following key-bind shortcut to detach from it: ctrl + a + d (C-a-d)

  • Hello, thanks for a contribution - looks good. Is that SCREEN following the -S a screen name (<screen name>)? Also what is the "stuff" parameter? Jul 21, 2021 at 10:21
  • 1
    @DannyStaple stuff string Stuff the string string in the input buffer of the current window. This is like the "paste" command but with much less overhead. You cannot paste large buffers with the "stuff" command. It is most useful for key bindings. See also "bindkey". Sep 22, 2021 at 17:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .