How to run a script inside a screen

How to run a script inside a screen

Hi people. Today i am going to teach you some linux commands. Lets say if you want to run a nodejs server inside your linux server. We can simply use following command to do it.

node filename.js

But, when you close the terminal, this script will stop running. So how to put this script keep running inside the server. To do that we are going to use “SCREEN”. First you need to install screen to your linux server.

sudo apt-get install screen

Then use following command to start a screen session.


then run your script. If your script is a nodejs based one, you can use

nodejs scriptName.js

Then press CTRL+a and after that CTRL+d to exit from the screen. Then you can check your screen is working or not by using below code.

screen -ls

it will show you the list of active screens.



Now your screen is live and you are safe to exit from your terminal. If you want to go inside a live and running screen(Resume your screen), just use below code. For that you will need the screen id. You can find the screen id when you execute the screen -ls command. In here, my screen id  is 7846. Lets resume in to the running screen now.

screen -r  7846

We are inside the screen now. There are two ways you can remove running screen. You can just close the terminal while you are inside the screen or you can use below command. you need the screen process id to this also. in my case, it is 7846.

screen -S 7846 -X quit

I hope you all enjoy the simple quick tutorial about the screens. Hope to join with you with another tutorial. Cheers.

I am Pasindu dineth peiris and im working as a software engineer. Im mainly working as a mobile application developer, but i love to work with python and other languages also. Im good with android, ios and also with cross platform frameworks like ionic 2, Nativescript, Fusetools. Using this website i am going to teach what i learn. KIT..

Leave a Reply

Your email address will not be published. Required fields are marked *