-
Notifications
You must be signed in to change notification settings - Fork 4
Using "screen"
A typical problem when connecting to a remote machine is that if the connection drops, the remote server will believe we are no longer interested in it and will kill our session. If we were performing some analysis, it would be terminated and we'd have to run it again.
Sometimes the analysis is long, and even if we have a stable connection we need to keep our computer on
just to let the remote server know we don't want to close the session.
There is a handy tool to make our life easier: screen
.
With screen
we can create a terminal that will not disappear when we disconnect from a machine,
and that will wait for us to come back when reconnecting to the server.
In this section we'll see how to
- create a new working session,
- how to connect to an existing session and
- some tricks to use screen as a pro.
-
Log in to the remote machine.
-
⚠️ First of all, we have to check no other screen session is active:screen -list
-
If the previous command gives no output (or a message like No Sockets found in …), then we can create a new screen, otherwise we need to attach to the previous session:
- To create a new screen session, type this command:
screen -S course
. With the -S switch we gave our session a handy nickname (“course”), but it's not mandatory to do so, but can be very helpful.
- To create a new screen session, type this command:
-
Now we are inside our "screen" and we'll have to press ENTER to get rid of a welcome text. If we close the terminal window, we don't lose what we were doing.
- To re-attach to our previous screen:
screen -dr course
Since the screen program shows us a Linux terminal, when we type we are talking to the terminal itself. So to interact with screen we need a special shortcut: Ctrl + A
. This triggers screen to listen to us. Then we can type a second key to specify what we needed:
-
Ctrl + a
,c
to create a new terminal inside our session -
Ctrl + a
,p
to navigate to the previous terminal -
Ctrl + a
,n
to navigate to the next terminal -
Ctrl + a
,d
to detach from the session: we'll return back to the “parent” terminal where we can reattach to the screen session with screen -r course.
For a more information you can read this article about screen.
· Bioinformatics at the Command Line - Andrea Telatin, 2017-2020
Menu