How to use Linux screen

Have you ever implementation of a long-running tasks on a remote computer, and suddenly disconnected, SSH session is terminated and your work is lost. Well, it happened at some point in all of us, is not it? Fortunately, there is a utility called the screen allows us to resume our conversation.

Introduction

GNU screen or screen is a terminal multiplexer. In other words, this means that you can start the conversation screen, and then open any number of windows (virtual terminal) in the session. Even if you disconnect when its window is not visible, a process running on the screen will continue to run.

Install Linux screen

Now on most Linux distributions preinstalled screen package. You can by typing the following if it is installed on a system to check:

screen --version
Screen version 4.06.02 (GNU) 23-Oct-17

If the screen is not installed on your system, you can use the distribution's package manager easy installation.

Installation on the screen and Debian

sudo apt install screen

And on the installation screen

sudo yum install screen

Start Linux screen

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

screen

This will open a screen session, create a new window and start a shell in the window.

Now that you have opened a screen session, you can get a list of commands by entering the following command:

Ctrl+a ?

Named session

When running multiple screen sessions, naming the session very useful. To create a named session, run screen command with the following parameters:

screen -S session_name

Select a meaningful conversation descriptive names are always a good idea.

Use Linux Screen Windows

By default, when you start a new screen session, it creates a single window that contains the shell.

You can have multiple windows in a screen session.

To create a new shell window of type Ctrl + ac, will be in the range 0 ... 9 assign the first available number to it.

Here are some Linux Screen Windows to manage the most common commands:

  • Ctrl + ac create a new window (with shell)
  • Ctrl + a "List all windows
  • Ctrl + a 0 window switch to 0 (by number)
  • Ctrl + a A rename the current window
  • Ctrl + a S region currently divided horizontally into two regions
  • Ctrl + a | vertical current region into two regions
  • Ctrl + a tab to switch the input focus to the next field
  • Ctrl + a Ctrl + a switch between the current and previous region
  • Ctrl + a Q Close all other region other than the current area
  • Ctrl + a X off the current region

Separated from the Linux screen session

You can always separate from the screen session by typing the following:

Ctrl+a d

After separation from the session, a program running in a screen session will continue to run.

Reconnect to the Linux screen

To restore the screen session, use the following command:

screen -r

If you run multiple sessions on your computer screen, you will need additional screen session ID after r.

To find the screen session ID, you can use the following command to list a list of currently running:

screen -ls
There are screens on:
    10835.pts-0.linuxize-desktop   (Detached)
    10366.pts-0.linuxize-desktop   (Detached)
2 Sockets in /run/screens/S-linuxize.

If you want to restore 10835.pts-0, type the following command:

screen -r 10835

Custom Linux screen

If the / etc / screenrc ~ .screenrc file exists and /, when the screen starts to read from its configuration parameters. We can set the default screen according to our own preferences modified by .screenrc file.

The following is an example ~ / .screenrc configuration, status line and have customized several additional options:

〜/.screenrc

# 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}]'

The basic usage of Linux screen

The following are the basic steps to start using the screen:

  1. At the command prompt, type screen.
  2. Required to run the program.
  3. Using the key sequence Ctrl-a + Ctrl-d separated from the screen session.
  4. Type can reconnect to the screen session screen -r.

in conclusion

In this tutorial, you learned how to use the Gnu Screen. You can now start using the Screen utility to create multiple sessions from a single window screen, navigate between windows, separation and recovery screen session and use .screenrc file personalize your screen terminals.

In the screen the user manual page there are a lot of knowledge about the Gnu screen.

Guess you like

Origin www.linuxidc.com/Linux/2019-08/159958.htm