Screen was a popular Linux command-line tool back in the day for launching and managing multiple shell sessions or splitting the screen vertically or horizontally across multiple terminal instances within a single terminal window manager.
This way, you are allowed to manage multiple shell sessions within a single SSH session, run a program in the background, maximize workspace efficiency, monitor various command statuses on one screen, and more.
However, later it was replaced with better tools such as Tmux or Zellij, and now there are many advanced terminal emulators available that provide built-in multiplexers that require zero learning curves, such as Tilix, Wave, Wrap, etc.
If you seek my advice and youβre a beginner stumbling upon this article without knowledge of Screen or Tmux, I recommend learning to use Tmux instead of Screen. And if youβre already familiar with Tmux and other tools, you can learn to use Screen for fun.
In this tutorial, Iβll show you how to install a screen on Linux and then how to use it with different examples.
Tutorial Details
| Description | Screen |
| Difficulty Level | Low |
| Root or Sudo Privileges | No |
| OS Compatibility | Ubuntu, Manjaro, Fedora, etc. |
| Prerequisites | β |
| Internet Required | Yes (for installation) |
How to Install Screen on Linux
On certain Linux distributions, screen comes preinstalled, and to verify, you can run the βscreenβ command. However, if you encounter the βscreen: command not foundβ error, use one of the following commands, depending on your Linux distribution, to install screen.
# On Debian, Ubuntu, Mint, Pop!_OS, etc.
$ sudo apt install screen
# On RHEL, CentOS, Fedora, Rocky Linux, AlmaLinux, etc.
$ sudo yum install screen
# On Gentoo Linux
$ sudo emerge -a sys-apps/screen
# On Alpine Linux
$ sudo apk add screen
# On Arch Linux
$ sudo pacman -S screen
# On OpenSUSE
$ sudo zypper install screenOnce the installation is complete, the βscreenβ command becomes accessible.
Usage of Screen
The screen command takes three arguments: the first is the option, the second is the command, and the third is the arguments (all of which are optional).
$ screen [options] [command [arguments]]Now, letβs see some practical examples on the usage of the βscreenβ command.
1. To start a screen session, simply enter the βscreenβ command without any options; it will present an interface identical to the command prompt.

2. Once youβre on the screen, you can start creating multiple windows or splitting screens, but all of this requires knowing the correct key combinations. In this article, Iβll show you most of it, but if you ever forget them, you can press βCtrl+aβ and then β?β to open the screen key bindings page.

3. As of now, youβre operating within a single window, but you can open multiple windows within a single-screen session by using βCtrl+aβ and then βcβ. This is particularly handy when youβve initiated a single SSH session thatβs already occupied and need to open a new window without reinitializing the SSH session.

4. When you create a new window in an existing screen session, thereβs no visual change, causing confusion in identifying the current working window. To address this, you can use βCtrl+aβ and then β"β (double quote) to list all created windows, with the active one highlighted.

5. To navigate between different windows, you can use either arrow keys or βjβ and βkβ while listing all windows using the previous method, or use βCtrl+aβ with βnβ (to move forward) and βpβ (to move backward) within the active window.
6. By default, the names of the window titles are set to the program that created them (often bash), but to distinguish each window, you can rename them. First, enter to desired window, then use βCtrl+aβ followed by βShift+aβ, it will open a prompt titled βSet Window's title to: <title>β. Provide your desired title and press enter to save.

Once you rename the window title, youβll find a new title that will make it more distinguishable when you list all the windows.

7. To terminate an active window session, use βCtrl+aβ followed by βkβ; it will ask for confirmation, where you should press βYβ for yes.

8. You can split the screen horizontally by using βCtrl+aβ and then βShift+sβ; to jump between them, use βCtrl+aβ and then βTabβ; lastly, to close the active window, use βCtrl+aβ and then βShift+xβ.

9. To split the screen vertically, use βCtrl+aβ and then βShift+|β; to jump between them, use βCtrl+aβ and then βTabβ; lastly, to close the active window, use βCtrl+aβ and then βShift+xβ.

10. To detach the screen session, you can use βCtrl+aβ and then βdβ; this way, you can avoid terminating all the running programs inside the screen.

11. To list all detached screen sessions, use the βscreen -lsβ command; furthermore, you can list all the running processes on your system and filter the output to display only those with the βSCREENβ command.

12. To reattach the screen session either you can use the βscreen -r <process-id>β command or just execute the βscreen -rβ command to reattach the most recently detached screen session.
13. If youβve accidentally detached multiple screen sessions and now want to terminate them, the first method is to reattach them and use the βexitβ command to quit, or alternatively, you can use the following command to terminate all detached screen sessions at once.
$ screen -ls | grep Detached | cut -d. -f1 | awk '{print $1}' | xargs killOutput:

14. The screen allows locking the current session with the user login password, so to lock it, use βCtrl+aβ and then βxβ; this will show the following prompt for the user login password to unlock.

15. The screen has a built-in mechanism to log every action during the session recording, eliminating the need to log each executed command individually and making it useful in debugging. To start screen logging, simply use βCtrl+aβ and then βShift+hβ, which will also display the log file location at the bottom.

When you quit the screen session or stop the screen logging by using the same βCtrl+aβ and then βShift+nβ key combination, it will stop recording and append all the changes to the file displayed during the start of recording. To view the log, you can simply use the βcatβ or βbatβ commands.
Final Word
Today, most users might not use the screen, but it was once a great tool. Now, if you have any questions or queries related to the article, you can ask them in the comment section.
Till then, peace!




