How To Install and Use Linux Screen Command

In this guide, we want to teach you How To Install and Use the Linux screen Command with examples.

screen command in Linux provides the ability to launch and use multiple shell sessions from a single ssh session. When a process is started with ‘screen’, the process can be detached from the session & then can reattach the session at a later time.

When the session is detached, the process that was originally started from the screen is still running and managed by the screen itself. The process can then re-attach the session at a later time, and the terminals are still there, the way it was left.

Steps To Install and Use Screen Command in Linux

In this guide, you will learn how to install and use Screen on a Linux system.

To complete this guide, you need a user account with sudo privileges and access to a command line/terminal window (Ctrl+Alt+t/Ctrl+Alt+F2).

Install Linux screen Command

By default, the screen command is installed on your Linux system. To verify it, use the command below:

screen –version
Example Output
Screen version 4.08.00 (GNU) 05-Feb-20

If you don’t have the screen installed on your server you can use the following commands:

On Centos 7 and RHEL 7, you can use the following command:

sudo yum install screen

On Debian and Ubuntu, you can use the command below:

sudo apt install screen

Start Linux Screen Command

To start your screen command, you can simply run the command below:

screen

The above command creates a new window by starting a shell in that window and opening a screen session.

To see the help screen, you can use the command below:

screen --help

In your Output you will see:

Output
-i            Interrupt output sooner when flow control is on.
-l            Login mode on (update /var/run/utmp), -ln = off.
-ls [match]   or
-list         Do nothing, just list our SockDir [on possible matches].
-L            Turn on output logging.
-Logfile file Set logfile name.
-m            ignore $STY variable, do create a new screen session.
-O            Choose optimal output rather than exact vt100 emulation.
-p window     Preselect the named window if it exists.
-q            Quiet startup. Exits with non-zero return code if unsuccessful.
-Q            Commands will send the response to the stdout of the querying process.
-r [session]  Reattach to a detached screen process.
-R            Reattach if possible, otherwise start a new session.
-s shell      Shell to execute rather than $SHELL.
-S sockname   Name this session <pid>.sockname instead of <pid>.<tty>.<host>.
-t title      Set title. (window's name).
-T term       Use term as $TERM for windows, rather than "screen".
-U            Tell screen to use UTF-8 encoding.
-v            Print "Screen version 4.08.00 (GNU) 05-Feb-20".
-wipe [match] Do nothing, just clean up SockDir [on possible matches].
-x            Attach to a not detached screen. (Multi display mode).
-X            Execute <cmd> as a screen command in the specified session.

In the output, we can see all the parameters or commands on the screen.

Linux Screen keystrokes

Once you launch Screen, the application creates a window with a shell inside of the screen session. You can add, switch, and manage windows using command keystrokes.

The most commonly used keystrokes include:

  • Ctrl + a and c – Open a new screen window.
  • Ctrl + a and  – List all open windows.
  • Ctrl + a and 0 – Switch to window 0 (or any other numbered window).
  • Ctrl + a and A – Rename the current window.
  • Ctrl + a and S – Split the screen horizontally, with the current window on top.
  • Ctrl + a and | – Split the screen vertically, with the current window on the left.
  • Ctrl + a and tab – Switch focus between areas of the split screen.
  • Ctrl + a and Ctrl + a – Switch between current and previous windows.
  • Ctrl + a and n – Switch to the next window.
  • Ctrl + a and p – Switch to the previous window.
  • Ctrl + a and Q – Quit all other windows except the current one..
  • Ctrl + a and X – Lock the current window.
  • Ctrl + a and H – Create a running log of the session.
  • Ctrl + a and M – Monitor a window for output (a notification pops up when that window has activity).
  • Ctrl + a and _ – Watch a window for the absence of output (such as when a file finishes downloading or a compiler finishes).

Named Sessions with Linux Screen

when you are working with the screen command, it is recommended to name each session. This helps you keep track of instances if you have multiple screen sessions running.

You can use the following command to launch and name a new session:

screen -S session_name

To create a session named upgrade, you run the command below:

screen -S upgrade 

Detach Linux Screen Session

You can easily exit the screen session in Linux but still, the running program continues to work. To do this, you can simply use the following keystroke:

Ctrl+a d

Reattach Linux screen Session

At this point, you can easily reattach the screen session without losing anything you have done in the Screen session by using the command below:

screen -r

Also, you can use the following command to display the screen session running in the background and the currently opened screen:

screen -ls

From the output you will get, you can restore the screen session by its ID:

screen -r session-id

Customize Screen

Like many Linux applications, Screen uses a customizable configuration file. Find the system-wide configuration file at /etc/screenrc. The user’s configuration file is located at ~/.screenrc.

To edit, you can open the file by using the command below:

sudo vi /etc/screenrc

Most of the settings can be toggled by removing the comment (#) sign at the beginning of the line.

Important Note: The `screen` package is deprecated and not included in RHEL8. Instead, you can use the tmux package.

In future guides, we will show you how it works.

Conclusion

At this point, you have learned to Install and Use Linux Screen Command with Examples.

Hope you enjoy it.

You may be like these articles:

Check Installed Linux Kernel in Command Line

Check What Service is Listening on a Specific Port on Linux

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Stay informed and not overwhelmed, subscribe now!