I'm starting the first command in screen like this:
screen -d -m -S testen -t lalala watch df -h
which gives me a screen session running in the background and I can reconnect at a later time.
How can I run a second command in a new window in the same screen session?
Best Answer
Start a named screen session (
-S
) with a named window (-t
) adapting to the terminal size (-A
) in detached mode (-d -m
):Start another named window (
-t
) in the same screen session (-S
):Stuff a few commands (
-X stuff $'cmds'
) into the first named window (-p
) in the session (-S
):Stuff a few commands (
-X stuff $'cmds'
) into the second named window (-p
) in the session (-S
):List the screen sessions and reattach to see what happened:
Note: The linefeed (
\n
) simulates pressing Enter. You could use semicolons to separate commands as well.