Lets learn "About screen command in linux"

 

In this tutorial, we'll learn about the screen command in Linux. Before proceeding to the tutorial I would also recommend going through a small tutorial on tty files in Linux which is available here. Screen command in Linux is helpful to open tty files. 

Introduction

The Screen is a full-screen program that multiplexes a physical terminal between several processes (typically interactive shells). It offers a user to open several separate terminal instances inside a one single window manager.

Installation

To install a screen on your system, run the below commands.

On Debian based systems

$ apt get install screen

On Red Hat based systems

$ yum install screen.

Running screen for the first time

$ screen

The command will open up a new terminal instance from the current terminal. To verify it you can check the tty (terminal) files. You will see a new tty (terminal) file being created. Checkout this for more info on tty files.

To exit from the terminal opened by screen press 'Ctrl + A' followed by 'K', it will prompt for confirmation if you really wanna kill the panel. Enter 'y' (or yes) to confirm. tty file that was created will be removed automatically.

Screen Shortcuts

To check all the shortcuts on the terminal press 'Ctrl + a' followed by '?', it will show all the shortcuts/parameters in Screen terminal.


Detach a screen

As we discussed how to exit from a screen opened terminal, sometimes you don't wanna exit but wanna switch terminals. The Screen helps you to do that by detaching a session. 

Consider an example where you are working on something and you are building the code which can take sometime. Meanwhile, you wanna work on something else without cancelling the running build.
To do that you can simply detach the terminal and you can re-attach it when you wanna continue work on that after the build is finished.

To detach from a terminal opened by screen program, run "Ctrl + A" followed by the "D" command.

To look at all the detached sessions, run the below command. It will list all the detached sessions. It basically prints all the tty files created by Screen.

$ screen -ls

Re-attach a Screen

Now that we know how to detach a screen session, we also need to know how to re-attach to the detached session.
If you have single-detached session, the below command will help you to re-attach it.

$ screen -r

But if you have multiple detached sessions, you can list all the sessions first and then pick the session you wanna attach to.

$ screen -ls
There are screens on:
10418.ttys001.rajat (Detached)
60989.ttys006.rajat (Detached)
2 Sockets in /var/folders/qj/8rdqs_750yn7f_3m2nx1wms80000gn/T/.screen.

$ screen -r ttys006



HOPE YOU LIKE THIS TUTORIAL. FEEL FREE TO COMMENT BELOW IF YOU HAVE ANY DOUBTS. AND STAY TUNED FOR MORE TUTORIALS :)

Comments

Popular posts from this blog

Lets learn "About kube proxy in iptables mode"

Lets learn "System design for paste bin (or any text sharing website)"

Lets learn "What is CDN?"