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.
Here at Ibmi Media, as part of our Server Management Services, we regularly help our Customers to perform related Linux System queries.
In this context, we shall look into the common usage of screens in Ubuntu 20.04.
Basic Linux Screen Usage
Below are the most basic steps for getting started with screen:
- On the command prompt, type screen.
- Run the desired program.
- Use the key sequence Ctrl-a + Ctrl-d to detach from the screen session.
- Reattach to the screen session by typing screen -r.
How to Install screen application on Ubuntu ?
To Install screen application, Run the following command:
$ sudo apt-get update
$ sudo apt-get install screen
To verify the installation of the screen, run the following command.
$ screen --version
How to 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.
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.
$ screen -S example-screen
How to List screen processes ?
We have started a new window using the screen command. Now to display all the current opened screens run the command:
$ screen -ls
How to 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 :
$ screen -S linuxapt-example
How to 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:
$ screen -r 4351
$ screen -r example-screen
How to List screen parameters ?
You can list all the screen parameters using ctrl+a followed by character ? .
How to 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.
How to 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.
How to Unsplit the screen ?
Splitted screen either vertically or horizontally can be unsplited by pressing ctrl+a followed by Q (uppercase q).
How to 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.
How to Terminal screen session ?
To terminate the current screen session, press ctrl+a followed by k (lowercase k) .
How to Check all the options available with screen command ?
To check all the options available with screen command, run the following command in your terminal:
$ screen --help
How to 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:
$ ls -lthr /var/run/screen/
How to Check the man page of Screen command ?
To check the man page of screen command, run man screen command as:
$ man screen
[Need assistance in fixing Linux Software Installation errors ? We can help you. ]