What is a Screen?
A terminal multiplexer is referred to as screen. Multiple interactive shells of the physical terminal are multiplexed by the screen. It permits the user to perform several tasks running in each terminal. All of these independent screen sessions execute their programs. If you accidentally closed or get disconnected from any screen session, that process will run within the screen session.
For example, when upgrading an Ubuntu server via SSH, if your SSH session is terminated for any reason, the screen command will continue the upgrade process undoubtedly.
Here, we have provided you a list of important keyboard shortcuts for managing various nested sessions.
Function | Keyboard Shortcut |
Showing keybindings | Ctrl+a ? |
Ending session and terminating Screen | Ctrl+a \ |
Closing the current session | Ctrl+a X |
Closing all sessions except the current one | Ctrl+a Q |
Splitting current region vertically into two regions | Ctrl+a l |
Splitting current region horizontally into two regions | Ctrl+a S |
Switching to session number 0 | Ctrl+a ” |
Switching to the previous session | Ctrl+a p |
Switching to the next session | Ctrl+a n |
Listing all sessions | Ctrl+a 0 |
Now, we will demonstrate to you the complete procedure of closing an existing screen session. Before starting this, check out the below-given method for setting up some screen session.
$ screen -dmS my_session_2
Setting-up Screen Sessions
As a result of the command execution, two sessions will be initialized named “my_session_1”, and “my_session_2”.
Now, list out all screen sessions by writing out the following command:
Here, the output will also give you information about the existing screen session, other than the newly created one.
One method of ending a session is to attach it first and then end it. We will follow this method in the upcoming section. We took “my_session_1” as an example, you can choose the session which you want to end.
Utilize the following command for checking related information about the “my_session_1” screen session.
Closing a Screen Session
Method 1:
Note the complete id of the screen session. After that, attach this screen session using the “-r” option in the screen command.
In your terminal, type “exit” to exit this screen session.
As you can see, the output declares that the process is terminated successfully.
Method 2:
Another method of ending a screen session is to press “CTRL+a” combined with the “\” key while a session is attached.
Conclusion
The screen multiplexes numerous interactive shells of the physical terminal. It also allows its user to execute multiple tasks in each terminal simultaneously. There comes a case where cleanup is required and for that, you want to end a screen session. In this post, we have discussed two distinct methods for ending a screen session.