In this article, we will learn about the most popular Terminal multiplexers that are Tmux and Screen. We will first learn what these tools are, along with some of their features and working. In the end, we will compare both tools.
We are using Debian 10 OS for explaining the procedures discussed in this article.
Tmux short for Terminal Multiplexer allows you to manage multiple Terminal sessions simultaneously instead of just one. You can easily switch between multiple programs from a single Terminal. It is really helpful when you are engaged in a complex project that requires several Terminals. With Tmux, you can attach and detach sessions when required. This allows to keep running the processes on servers without interrupting any task.
Features of Tmux
Some of the features of Tmux are as follows:
- It can be run on the Mac, Linux, Raspberry Pie, BeagleBones, etc.
- Easily customizable, you can change the look and behavior of your Tmux environment
- Highly configurable, you can manually add custom configuration for different features
- Its key feature is it windows that are like tabs in browsers.
- Each window is like a separate Terminal whereby different commands can be run at the same time.
- It facilitates several windows and panes in a single Terminal window.
- Maintains windows and panels in a session (that stays active even when the network is disconnected)
- It supports both Emacs and Vim shortcuts
- Offers a wide range of shortcut keys which can be very helpful for regular use of applications.
- Can detach the Terminal interface without disrupting the service running in the background and re-attach it when required.
Installation of Tmux
Tmux is included in the official Debian repositories. We can install it using the apt-get command in Terminal. Launch the Terminal in your Debian OS. In the top left corner of the desktop, go to the Activities tab. Then type terminal in the search bar. When the Terminal icon is displayed click it to open.
Now in order to install Tmux, execute the following command in Terminal:
When prompted for the password, enter sudo password.
Once installed, launch the Tmux by simply typing tmux in the Terminal as follows:
By running the above command, a new session will be started. At the bottom of the session window, you will notice a green-colored status bar containing some info. Let’s see what that means:
-  0:bash : Indicates we are running bash, with session number 0 and the window number/name 0
- *: Indicates this is the current window
- “Linux-debian” : Indicates the hostname
- 01:30 : Indicates the current time
- 06-Dec-19 : Indicates the current date
First, we need to learn how Tmux works. The most basic steps to get started with Tmux are below:
Open a session by typing tmux new -s my_session in the Terminal
- Complete your desired work.
- Once done, detach the session using the Ctrl-b + d shortcut. Commands and programs will continue to run even you detach the session.
- When you want to reattach to the Tmux session, simply type tmux attach-session -t my_session in the Terminal.
Creating Named Sessions with Tmux
Tmux labeled its sessions numerically. When dealing with multiple sessions, you can also assign them names. Execute the below command in Terminal to build a named session.
For instance, to create a session with the name tin, the command would be:
In the following screenshot, you can see the status bar showing the name of the session at the bottom left corner.
Splitting Tmux vertically
In order to split Tmux vertically; use (Ctrl-b) + %. After that the Screen will be splitted vertically.
Splitting Tmux horizontally
In order to split Tmux horizontally, use (Ctrl-b) + “. After that, the Screen will be splitted horizontally.
You can also simultaneously split windows both horizontally and vertically.
GNU Screen is another Terminal multiplexer program that allows managing several Terminal sessions from with the single window. Similar to Tmux, you can also attach/detach your sessions. Along with this, it enables you to share your session with other users.
- Keep programs and scripts running even when the network get disrupted.
- Detach and reattach to a Terminal session from various sites.
- Carry out a long-running program without keeping an active shell session.
- Allows to share the session with other users
- Splitting the Terminal window horizontally and vertically
- Offers a wide range of shortcut keys
The screen is included in the default Debian repositories. We can use the apt-get command to install it. Launch your Terminal application and execute the following command to install Screen:
When prompted for the password, enter the sudo password.
Once installed, simply type screen in the Terminal as follows:
Type Ctrl-A and ?, all the commands will be listed on the screen.
A named window will be started within the screen. Later this same name will be used to reattach screen.
This command lists the currently opened screens which includes both attached and detached Screen sessions.
This command can be used for detaching a current Screen session in order to re-attached in future.
This command can be used for re-attaching a Screen session that was detached previously.
Switch between windows
It is used to move to a next window. If you want to move to the previous window, use “Ctrl-A” and “p”.
List opened windows
It is used to list the opened bash windows.
Use “Ctrl+a” “|” to split the current window horizontally. It will only split the window but will not create a session. Use “Ctrl+a” “Tab to switch to that region and the use Ctrl+a” “c” to start a new session.
Use “Ctrl+a” “S” (Capital S) to split the current window vertically. Use “Ctrl+a” “Tab to switch to that region and the use Ctrl+a” “c” to start a new session.
Comparison between Tmux and Screen
Based on the above discussion, we can conclude that both programs: Tmux and Screen approximately serves a similar purpose. Both programs build a virtual Terminal inside a single Terminal, allows you to switch among virtual Terminals and let you attach and reattach the virtual Terminals when your network connection is disrupted. Both programs operate by building separate processes which they name differently.
However, there are some differences as well among these two tools. Tmux has a BSD license while the Screen has GNU GPL. Tmux is more user-friendly than the Screen and contains a nice status bar with some info in it. Tmux features automatic window renaming while the Screen lacks this feature. The Screen allows session sharing with other users while Tmux does not. That is the great feature that Tmux lacks.
We may therefore conclude that just like any program, this truly relies on your requirements and preferences and with which you feel more comfortable with. Give both of them a try and sew what best fit your needs.