The Multiplexer of a terminal is known as a screen; these are the multiple interactive shells of the terminal. It enables the user to perform various operations running in every terminal. The main benefit of using the screen is if the user disconnects or accidentally closes the screen session, it will still run the process in the screen session. Let’s say the user wants to
This article will demonstrate the methods to close a screen session in Linux. The content for the post is:
- Creating the Screen Session
- Method 1: Close a Screen Session Using “-r” Flag
- Method 2: Close a Screen Session Using the Shortcut key
Creating the Screen Session
Linux screen gives the facility to open various separate terminals by staying in the single terminal session. It also provides some extra functionalities and features for the commands. For creating the screen in Linux, let’s install the apt package of the screen command using the given command.
For Debian/ Ubuntu:
$ sudo apt install screen
$ yum install screen
The screen utility will be installed in the operating system. Let’s check the version of the screen utility:
$ screen --version
The screen version 4.09.00 is available in the operating system.
Let’s move and create some screen sessions:
$ screen -dmS session_1 $ screen -dmS session_2
Two screen sessions, “session_1” and “session_2,” have been created.
To check the created screen sessions, users can use the “-list” flag with the screen command:
$ screen -list
The above image shows the created session with their session IDs.
Now, let’s move towards removing the methods of the screen.
Method 1: Close a Screen Session Using “-r” Flag
To remove the created screen in Linux, use the “r” flag with the screen command and the screen session with its ID:
$ screen -r 4177.session_1
Once you type the command and hit the enter button, it will take you to another terminal.
Type the exit command and press Enter:
After pressing the enter button, you will be exited from the current terminal, and the message will be displayed:
The screen session has been terminated, as shown in the above image.
Method 2: Close a Screen Session Using the Shortcut key
Another method to close a screen session is using the shortcut key (Ctrl+A+D). Let’s apply this method in session 2, which we have created in the above section. Run the same command with the “r” flag that we have executed in method 1:
$ screen -r 4185.session_2
This will take you to the created screen session. Press the “Ctrl+A+D” shortcut key from the keyboard. The screen session will be terminated as shown in the below GIF:
To remove the created screen sessions in Linux, run the screen command using the “r” flag with its session ID and then type exit or use the shortcut key “Ctrl+A+D” from the keyboard. This write-up has illustrated the methods for creating and removing the screen sessions in Linux.