Exit the detached screen:
screen -X -S [session # you want to kill] quit
How to go to a screen:
screen -r [session]
How to detach:
ctrl+a d
Create a new screen into another screen:
ctrl+a c
Move between screens:
ctrl+a n/p
Kill detached:
screen -X -S SCREENID kill
Send command to the running previus screen
screen -S yoursession-name -p 0 -X stuff "ls^M" --> put your command in "" and put ^M
If you omit ^M, screen will just type ls onto your terminal but not send the ENTER key afterwards.
Run a command in screen without attaching
screen -S something -d -m ping 8.8.8.8
Copy mode
ctrl-a escape
with -h you can specifie the number of lines that you want to keep, if the output is huge set it to high number
https://raymii.org/s/snippets/Sending_commands_or_input_to_a_screen_session.html