Thursday, October 6, 2022
Google search engine
HomeLinux TutorialsHow To Use Linux Screen

How To Use Linux Screen

With the Linux screen command, you can push running terminal applications to the background and pull them forward when you want to see them. It also supports split-screen displays and works over SSH connections, even after you disconnect and reconnect!

Introduction

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.

How Install Screen

Please follow your distribution installation procedure to install the screen.

sudo apt-get install screen       #On Debian, Ubuntu and Mint
sudo yum install screen           #On RHEL/CentOS/Fedora and Rocky Linux/AlmaLinux
sudo emerge -a sys-apps/screen    #On Gentoo Linux
sudo pacman -S screen            #On Arch Linux
sudo zypper install screen       #On OpenSUSE

and then check screen already installed on your system by typing:

screen --version

output

Screen version 4.06.02 (GNU) 23-Oct-17 

Starting Linux Screen

To start a screen session, simply type screen in your console:

screen

This will open a screen session, create a new window, and start a shell in that window. Now that you have opened a screen session, you can get a list of commands by typing:

Ctrl+a ?

Starting Named Session

Named sessions are useful when you run multiple screen sessions. To create a named session, run the screen command with the following arguments:

screen -S session_name

It’s always a good idea to choose a descriptive session name.

Start Working with Linux Screen Window

When you start a new screen session, it creates a single window with a shell in it. You can have multiple windows inside a Screen session.

To create a new window with shell type Ctrl+a c, the first available number from the range 0...9 will be assigned to it.

Below are some most common commands for managing Linux Screen Windows:

  • Ctrl+a c Create a new window (with shell).
  • Ctrl+a " List all windows.
  • Ctrl+a 0 Switch to window 0 (by number).
  • Ctrl+a A Rename the current window.
  • Ctrl+a S Split current region horizontally into two regions.
  • Ctrl+a | Split current region vertically into two regions.
  • Ctrl+a tab Switch the input focus to the next region.
  • Ctrl+a Ctrl+a Toggle between the current and previous windows
  • Ctrl+a Q Close all regions but the current one.
  • Ctrl+a X Close the current region.

Detach from Screen Session

You can detach from the screen session at any time by typing:

Ctrl+a d

Resume to previous Linux Screen

screen -x

list all screen

screen -ls

output

There are screens on:
    10887.pts-0.devninja-desktop   (Detached)
    10785.pts-0.devninja-desktop   (Detached)
2 Sockets in /run/screens/S-devninja.

Customize your Linux Screen

When screen is started, it reads its configuration parameters from /etc/screenrc and ~/.screenrc if the file is present. We can modify the default Screen settings according to our preferences using the .screenrc file.

This sample ~/.screenrc configuration with customized status line and few additional options:

# Turn off the welcome message
startup_message off

# Disable visual bell
vbell off

# Set scrollback buffer to 10000
defscrollback 10000

# Customize the status line
hardstatus alwayslastline
hardstatus string '%{= kG}[ %{G}%H %{g}][%= %{= kw}%?%-Lw%?%{r}(%{W}%n*%f%t%?(%u)%?%{r})%{w}%?%+Lw%?%?%= %{g}][%{B} %m-%d %{W}%c %{g}]'

YOU CAN SUPPORT DEVNINJA WITH A CUP OF COFFEE

As we continue to grow, we would wish to reach and impact more people who visit and take advantage of the guides we have on our blog. This is a big task for us and we are so far extremely grateful for the kind people who have shown amazing support for our work over the time we have been online. to search or browse the published articles available FREELY to all.

If you like what you are reading, please consider buying us a coffee ( or more ) as a token of appreciation.

Support Us

DevNinja
DevNinja
A systems engineer with experience in systems administration, cloud computing, systems deployment, virtualization, containers
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

twenty − six =

- Advertisment -
Google search engine

Most Popular

Recent Comments