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.

1 Answer 1


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.

  • Thank you very much, very helpful! I also learnt that this works, as a one-liner, to create a screen, start a command, and attach: screen -S myserver python myserver.py (previously I always did screen -S myserver and then typing the command manually).
    – Basj
    Feb 13, 2018 at 22:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.