Screen Command in Linux

Hello, world! Welcome to “TechBlog” In this Tech Article, we are going to learn about Screen command and its utility.

Introduction:

Have you ever faced a situation where you perform a long-running task on a remote machine, and suddenly your connection drops, the SSH session is terminated, and your work is lost. Well, it has happened to all of us at some point, hasn’t it? Luckily, there is a utility called screen that allows us to resume the sessions.

Screen Intro and Why Screen

More specifically we are going to discuss the following topic:

  • What is Screen Command
  • Install screen into Linux system
  • Command Flags, arguments, and Shortcuts
  • Practical use cases

What is Screen Command:

Screen or GNU Screen is a terminal multiplexer. In other words, it means that you can start a screen session and then open any number of windows (virtual terminals) inside that session. Processes running in Screen will continue to run when their window is not visible even if you get disconnected.

What is screen

Install screen into Linux system

it’s easy to install like anything else. It’s in the repos of every linux, so you have to do nothing special, you know, just type apt install screen. If you logged in with sudo user then use sudo before the command.

Installation of screen command: To install the screen command simply go to the terminal and type the following command:

sudo apt install screen

Install Screen

I have installed a screen in my system.

Command Flags, arguments, and Shortcuts:

Syntax:

screen [-opts] [cmd [args]]

Options:

    • -a: It force all capabilities into each window’s termcap.
    • -A -[r|R]: It adapt all windows to the new display width & height.
    • -c file: It read configuration file instead of ‘.screenrc’.
    • -d (-r): It detach the elsewhere running screen (and reattach here).
    • -dmS name: It start as daemon: Screen session in detached mode.
    • -D (-r): It detach and logout remote (and reattach here).
    • -D -RR: It do whatever is needed to get a screen session.
    • -e xy: It change the command characters.
    • -f: It make the flow control on, -fn = off, -fa = auto.
    • -h lines: It set the size of the scroll back history buffer.
    • -i: It interrupt output sooner when flow control is on.
    • -l: It make the login mode on (update /var/run/utmp), -ln = off.
    • -ls [match]: It display all the attached screens.
    • -L: It turn on output logging.
    • -m: It ignore $STY variable, do create a new screen session.
    • -O: It choose optimal output rather than exact vt100 emulation.
    • -p window: It preselect the named window if it exists.
    • -q: It quiet startup. Exits with non-zero return code if unsuccessful.
    • -Q: It commands will send the response to the stdout of the querying process.
    • -r [session]: It reattach to a detached screen process.
    • -R: It reattach if possible, otherwise start a new session.
    • -S sockname: It name this session .sockname instead of …
    • -t title: It set title. (window’s name).
    • -T term: It use term as $TERM for windows, rather than “screen”.
    • -U: It tell screen to use UTF-8 encoding.
    • -v: It print “Screen version 4.06.02 (GNU) 23-Oct-17”.
    • -x: It attach to a not detached screen. (Multi display mode).
    • -X: It execute as a screen command in the specified session.

Shortcut keys Options:

    • Ctrl-a + c: It create a new windows.
    • Ctrl-a + w: It display the list of all the windows currently opened.
    • Ctrl-a + A: It rename the current windows. The name will appear when you will list the list of windows opened with Ctrl-a + w.
    • Ctrl-a + n: It go to the next windows.
    • Ctrl-a + p: It go to the previous windows.
    • Ctrl-a + Ctrl-a: It back to the last windows used.
    • Ctrl-a + k: It close the current windows (kill).
    • Ctrl-a + S: It split the current windows horizontally. To switch between the windows, do Ctrl-a + Tab.
    • Ctrl-a + |: It split the current windows vertically.
    • Ctrl-a + d: It detach a screen session without stopping it.
    • Ctrl-a + r: It reattach a detached screen session.
    • Ctrl-a + [: It start the copy mode.
    • Ctrl-a + ]: It paste the copied text.

How to start a screen in Linux:

Generally, to start a screen session you can simply type the screen on the terminal it will start a screen session for you. Here you can see their screen starting with some information like its version license details etc.

start screen

you can continue reading documentation by pressing the space bar or pressing the enter key to start the screen.

How to list running screen:

If you do screen -ls then it will display all available screen sessions running in your system.

screen list

How to specify screen name:

Actually screen has an option dash S. Using this you can name a screen session as you wish. For example, I am going to give it my session name “config”. ie. screen -S config

screen specific name

How to reattach running screen:

Now we reattach our running screen. So, the command is screen -R <screen ID>. this will bring you your running screen. So every time you just need to put Screen ID after flag R.

screen reattach

Practical use cases:

Let’s assume that you are in a situation where you need to monitor the running process in your system while at the same time you need to keep eye on your network traffic. and the other hand you need to install some script.

use of screen

 

View on Youtube:

And you can detach the entire screen any time and if you left the system still the process is running as usual in the background. You can resume screen any time as I earlier mentioned.  And this way the screen becomes a very useful tool in Linux. So, guys hope this article is helpful to you, Thank you.

 

The following two tabs change content below.

Subroto Mondal

Chief Coordinator HR&CR
I like Programming and New Technologies. And work with Linux.

Latest posts by Subroto Mondal (see all)

Leave a Comment

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.