Two years ago, I got introduced to this amazing terminal program called Screen.
Let’s check it out, shall we?
What is screen?
A terminal program in linux
Allows us to start a screen session, in which we can open multiple virtual terminal windows
When should we use this?
This is useful in situations where:
you want to keep your program running in background for a long time, and don’t want it to block your other work
For example -
Once I wanted to run a python server in a remote machine.
I realised that I can only work on a single terminal, since we could only interact with a remote machine via terminal.
So, I was trying to figure out a way such that my python server keep on running, without blocking the future work inside the remote machine.
That’s where screen came into picture. I started a new session for my server to run in background.
This made sure that the remote machine was unblocked for other operations.
FYI:
Screen keeps on running even after the terminal is closed.
Screen gets terminated when the machine is shut down.
Commonly used screen commands
(Run these commands inside your linux terminal)
Start a screen session
$ screen
Start a named session
$ screen -S test1
Useful to identify in case of working with multiple screens
Detach from a screen session - “control + a + d“
In case if you haven’t detached from a session successfully, you can also detach it from outside the screen using command -
$ screen -d <session_name>/<session_id>
Reattach to a screen session
$ screen -r test1
Can reattach to a screen session using the “name” of an already running screen session.
If a screen session name is not present, can use “screen id“ to reattach instead.
Terminate a screen session - “control + d“
List all screens
$ screen -ls
Get help
$ screen --help
That’s all folks. Hope this was interesting and helpful.
P.S. Can checkout the official documentation of Screen here.