GNU Screen – Create a Screen, Launch a Command, and Detach

command linegnu-screen

I'd like to do a one line bash command that automatically does this:

screen -S myserver 
python myserver.py  # inside the new screen
CTRL A, D (detach)

I think this won't work:

screen -S myserver && python myserver.py

because python myserver.py won't be started inside the screen.

Best Answer

You can detach right after starting a program inside of screen:

screen -dmS myserver python myserver.py

From screen's man page

-d -m Start screen in detached mode. This creates a new session but doesn't attach to it. This is useful for system startup scripts.

Related Question