Using “Screen”

A command I use a lot is the screen commaned. What does this do? It creates a completely separate session on the machine you are on. You can leave it and come back to it. Even if you log off the machine. To start type screen. It will take you into the new session. If you type exit it will take you back to the screen you were in. If instead you simply want to disconnect from the session but leave it running hit Ctrl + a then immeadiately hit the d key. You can recreate by running screen -r.

This is a very useful way of using sessions for two reasons. Firstly if you are on a wobbly connection (for example a mobile) or a connection that timers out. I use this on a server that is on a connection that disconnects after 5 minutes of inactivity. Fine for email or web browsing but annoying if you are using SSH and need to go do something else for a little while. If you are in one office and in the middle of working then need to head to another office you can disconnect and reconnect from somewhere else using the Ctrl + a d then screen -r.

For example you can run top in a session, disconnect and reconnect to find it still running. This brings us to the second use of the screen command. As a cheating way of running a daemon process. If you start a process running you can disconnect the session an leave it running. When you want to stop it reconnect and stop it.

It is oftn useful to create multiple sessions that you want to reconnect to. If you do that running screen -r will show you a list of sessions. For example –

22188.pts-16.xen1 (01/10/20 13:35:41) (Detached
22175.pts-16.xen1 (01/10/20 13:35:32) (Detached)

To reconnect to a particular session run

screen -r NAME

e.g.

screen -r 22188.pts-16.xen1

It is useful to name each of these sessions when you create then. You do this by using screen -S NANE for example screen -S database. Reconnect with screen -r database.

The only difference between a screen session and a normal session is when text spools off the screen you cannot just scroll back.