Start a named screen session (-S
) with a named window (-t
) adapting to the terminal size (-A
) in detached mode (-d -m
):
screen -S mySessionName -t myWinName0 -A -d -m
Start another named window (-t
) in the same screen session (-S
):
screen -S mySessionName -X screen -t myWinName2
Stuff a few commands (-X stuff $'cmds'
) into the first named window (-p
) in the session (-S
):
screen -S mySessionName -p myWinName0 -X stuff $'echo myWinName0\necho cmd1\necho cmd2\n'
Stuff a few commands (-X stuff $'cmds'
) into the second named window (-p
) in the session (-S
):
screen -S mySessionName -p myWinName1 -X stuff $'echo myWinName1\necho cmd1\necho cmd2\n'
List the screen sessions and reattach to see what happened:
screen -ls
screen -r mySessionName
Note: The linefeed (\n
) simulates pressing Enter. You could use semicolons to separate commands as well.