Screen command basics

Thu, 18 Apr 2024 17:11:46 GMT

The screen command is one of those linux commands that many newbs don't know about or don't see the usefulness of right away.
It is actually quite powerful.
If you ssh into a linux machine and want to start a process that stays running for a long time if your ssh session dies or
you need to log out the process will be killed.
However with screen you can keep it running in the background.

How to use screen:

You may need to install screen as it isn't installed by default on many distro's

Say you have a command that looks like this.
python dht11.py for example.

type screen python dht11.py
Screen will start the process running.

press ctrl A and then d to detach the screen and be returned to the command prompt.
The process is still running and you can log out of your ssh session.

Log back in and type screen -r to bring the process back to your terminal.

While i used an ssh session in my example the same applies if you are running an X terminal locally and need to close the terminal for a while.