Start a screen session
Detach from the screen session
Ctrl+a d (Hit Ctrl+a quickly followed by hitting just d)
List current screen sessions
$ screen -ls There is a screen on: 1119.pts-0.acer11 (Detached) 1 Socket in /run/screens/S-brm.
screen -list does the same thing.
Attach to this screen session
$screen - r
Attach to an already attached screen. That is , if the session is already attached by someone else or somewhere else. The other person will able to see what you type on the terminal, a nice way to share screen.
Terminate the screen session
(Ctrl+a k) (Hit Ctrl+a quickly followed by hitting k)
Alternate ways to terminate screen session is
exit as you would on a shell session. But only Ctrl+a k asks for confirmation like this:
kill this window [y/n]
After terminating a screen session, you should see something like this, you are taken back to the prompt where you started or attached the session.
[screen is terminating] $
Now there are no screen session.
$ screen -ls No Sockets found in /run/screens/S-brm.
Attach to a session when there are multiple sessions
There are three sessions here:
$screen -ls There are screens on: 1209.pts-0.acer11 (Detached) 1205.pts-0.acer11 (Detached) 1202.pts-0.acer11 (Detached) 3 Sockets in /run/screens/S-brm.
To attach to the middle one 1205.pts-0.acer11 (Detached):
$screen -r 1205.pts-0.acer11 or just $screen -r 1205
If the session is already attached by someone else, somewhere
$screen -x 1205
To name a session while starting for easy reference
$screen -S SessionName
SessionName given will now appear in screen -ls output
To change the window title
$screen -t Newtitle
I find this useful to see where I am.
How I can tell I am in a screen session and which session?
$ echo $STY 1209.pts-0.acer11
Compare the output from screen -ls. If you are not attached to any screen session, you get a blank output.