Linux screen show all screens

How to Use Screen Command to Manage Terminal Sessions in Ubuntu 20.04

How to Use Screen Command to Manage Terminal Sessions in Ubuntu 20.04

Sometimes we need to use multiple terminal sessions within one window while performing several tasks. Fortunately, In the Linux system, we have a console application “screen” which allows us to use multiple terminal sessions in a window. Using “screen” applications, it is possible to run any number of interactive command shells, console-based applications, etc. It is very useful to keep running the program even if you accidentally close the terminal.

For instance, you are working in a remote Linux machine using an SSH session, but many times you get the SSH session terminated and you lose the task you are working on. In this case, the screen utility tool helps to resume the session. In this article, we will learn about the common usage of screens in Ubuntu 20.04.

Installation

Installation of the screen application is a simple and straightforward process. Run the following command to install screen in Ubuntu 20.04.

$ sudo apt-get install screen

To verify the installation of the screen, run the following command.

Start screen session

By using a simple screen command, the screen session can be started. The command will create a new terminal inside the current running terminal and if you do not want to use it you can use the exit command to come out of the screen.

Читайте также:  Статистика популярности linux дистрибутивов

A new window can be started within the screen with the name as follows. In this example, I have used a screen name example-screen which can be reattached at a later stage.

List screen processes

We have started a new window using the screen command. Now to display all the current opened screens run the command:

Detach the current screen

You can use ctrl+a followed by d command to detach your screen session from the current terminal. Type control+a d in the terminal session as :

Reattach the screen session

You can reattach your detached screen session using screen command with -r option. From the list of the screen session, you can simply type screen -r and screen name to reattach the session again. In this example, I have reattached an 4351.example-screen session from my screen list. You can select your session accordingly.

$ screen -r 4351.example-screen

You can also attach the screen session using ID of the screen session or using name only as:

List screen parameters

You can list all the screen parameters using ctrl+a followed by character ? .

Split the screen vertically

The terminal window can be split either vertically or horizontally as per your convenience. To split the window vertically, press the ctrl + a followed by character | as in the screenshot. The same process can be repeated for n number of vertical screens.

To navigate to another screen type ctrl+a followed by Tab

Split the screen horizontally

To split the screen horizontally press ctrl + a followed by S (upper case). You can repeat the same process to get n number of horizontal screens.

Unsplit the screen

Splitted screen either vertically or horizontally can be unsplited by pressing ctrl+a followed by Q (uppercase q)

Create a new terminal in split session

Just after splitting the screen horizontally or vertically, it does not create any terminal automatically.Move to the new terminal session using key ctrl+a followed by Tab and press ctrl+a followed by c (lowercase c) to create a new terminal session.

Читайте также:  Проверить существует ли директория linux

Terminal screen session

To terminate the current screen session, press ctrl+a followed by k (lowercase k) as in the screenshot below.

Check all the options available with screen command

To check all the options available with screen command, run the following command in your terminal

Check the owner of the screen

To check the owner of the opened screen session, you can list the content of the directory /var/run/screen using ls -lthr /var/run/screen command as:

Check the man page of Screen command

To check the man page of screen command, run man screen command as:

Conclusion

In this article, we have learned how to use screen commands in ubuntu 20.04. If you have more screen command tips, do not forget to share them in the comment below.

Karim Buzdar holds a degree in telecommunication engineering and holds several sysadmin certifications including CCNA RS, SCP, and ACE. As an IT engineer and technical author, he writes for various websites.

Источник

Screen Command in Linux

Screen Command in Linux

  1. What Is screen Command in Linux
  2. Use screen Command to Start Screen in Linux
  3. Use screen Command to List All Screen Sessions in Linux
  4. Use screen Command to Attach Screen Session in Linux
  5. Use screen Command to Start Screen Logging in Linux

This tutorial explains using the screen command in Linux to create, attach, detach, log, and exit screen sessions.

What Is screen Command in Linux

The screen command is a bash program used to manage the Linux window. Using the screen command, you can initiate multiple screen sessions. The screen session can also have multiple windows.

The screen command helps separate processes running on the terminal by putting them in different sessions. The screen command allows you to switch between sessions and choose which session to attach.

Use screen Command to Start Screen in Linux

To start the screen program in Linux. Type screen as shown below and press Enter .

screen img1

The above command displays the following output. Press Space , and you will be directed to a terminal.

Читайте также:  Связка ключей linux браузер

screen img2

Once on the terminal, you can run commands as if you are in the normal terminal environment.

We are now inside a terminal session which we started using the screen command. To detach from the session, press Ctrl + A and D .

You will see similar output to the one below.

screen img3

Use screen Command to List All Screen Sessions in Linux

To list all the available screens on our machine, we use the screen command with the -ls or -list option.

The image below shows the available screens on our machine.

screen img4

Use screen Command to Attach Screen Session in Linux

We use the screen command with the -r option that takes the session ID as an argument to go back to the screen session after detaching it.

We reattach the session with ID 2276 in the image below.

screen img5

Use screen Command to Start Screen Logging in Linux

To enable logging when we start a screen session, we use the screen command with the -L option. It will create a log file for the screen session in the current screenlog.0 folder.

We start a new screen session with logging enabled in the image below.

screen img6

Once inside the screen session, we type the following commands, and then we detach the session by typing Ctrl + A and D .

screen img7

Now that we are outside of the session, we use the ls command to list the contents of the current directory and pass the output to the grep command. The grep command looks for the screenlog match and displays the line that fits the match.

The image below shows that we have the screen log file named screenlog.0 .

screen img8

To leave the screen terminal session, you can press Ctrl + A and D to detach the screen. You can also type the exit command on the terminal, and it detaches the screen.

Using Ctrl + A and K kills the screen.

Fumbani is a tech enthusiast. He enjoys writing on Linux and Python as well as contributing to open-source projects.

Related Article — Linux Command

Copyright © 2023. All right reserved

Источник

Оцените статью
Adblock
detector