How to create a screen executing given command?

You create a screen with a name and in detached mode:

screen -S "mylittlescreen" -d -m

Then you send the command to be executed on your screen:

screen -r "mylittlescreen" -X stuff $'ls\n'

The stuff command is to send keystrokes inside the screen. The $ before the string command is to make the shell parse the \n inside the quotes, and the newline is required to execute the command (like when you press enter).

This is working for me on this screen version:

$ screen -v

Screen version 4.00.03jw4 (FAU) 2-May-06

Please see man screen for details about the commands.

Leave a Comment