Hey there everyone have you ever run a service and wondered why the hell this service does not have detached mode ( detached mode means a service which runs in background and does not freeze your terminal ) so this is the one stop solution for you
What is screen command
You can assume screen command as a new screen for you inside terminal where can you create multiple virtual screen to run multiple services
This command is very useful if you are in server using ssh and want to run a service in background but service itself does not provide a detached mode. ( e.x. ElasticSearch )
If you have unix system ( linux or macos ) screen command should be available to you
To check screen command is available to you or not just run
screen -v
it it returns any version like this voila you have screen command installed.
Now let's have a look how it works
You can create a screen with below command
screen -S SCREEN_NAME
it will create a screen put you into that screen
to create a screen without entering into it you can run
screen -dmS SCREEN_NAME
it will create a screen but it won't go into screen
- Now that you have created a screen if you want to see a list of screen you have created you can use below command
screen -ls
it should give you the list of screens you have created!
Screen Version
- Now that you have created and listed out screens you can enter into any screen by typing below command
screen -dR SCREEN_NAME
in case you can see your screen in
screen -ls
command but unable to enter it try to enter into screen by using full name of screen with pid.SCREEN_NAME
pid is id which you can see in screen -ls command
- Now that you can created, listed and entered into screen and did you stuff now you want to make sure it runs in background so to come out from screen and run in background you have to press
CONTROL+A+D
by pressing this you will come out of screen and it will run in background
- How to delete a screen to delete a screen enter into the screen and press
CONTROL+D
it will terminate your screen and you will see an output like this
So this is all basics about screen command which you have inside your system to know more about it type
screen --help
you will get all the options available there.
Thanks for reading!
Top comments (3)
Great article and a great piece of software.
I also used to use sceen a lot.
Today, actually, almost only Tmux.
I don't even remember what spoke against screen at the time.
Sadly, Red Hat decided to remove
screen
from RHEL8 and newer. As someone whose customers are pretty much exclusively deploying on RHEL (or clones), this left me having to switch totmux
(and altering a bunch of finger-memory).Great tutorial! Well done!