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.

  • 1
    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
  • How to prevent the screen from terminating when the command is finished ? Thanks
    – KaKi87
    May 3 at 5:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .