Terminal

Tmux vs. Screen tool comparison

A Terminal multiplexer is a program that can be used to multiplex login sessions inside the Terminal. This allows users to have multiple sessions inside a single Terminal window. One of the important features of the Terminal multiplexer is that users can attach and detach these sessions.

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

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:

$ sudo apt install tmux

When prompted for the password, enter sudo password.

Launch Tmux

Once installed, launch the Tmux by simply typing tmux in the Terminal as follows:

$ tmux

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] 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

Using Tmux

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

  1. Complete your desired work.
  2. Once done, detach the session using the Ctrl-b + d shortcut. Commands and programs will continue to run even you detach the session.
  3. 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.

$tmux new -s session_name

For instance, to create a session with the name tin, the command would be:

$ tmux new –s tin

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.

Screen

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.

Screen Features

  • 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

Screen Installation

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:

$ sudo apt-get install screen

When prompted for the password, enter the sudo password.

Launch Screen

Once installed, simply type screen in the Terminal as follows:

$ screen

Type Ctrl-A and ?, all the commands will be listed on the screen.

$ screen -S file

A named window will be started within the screen. Later this same name will be used to reattach screen.

$ screenls

This command lists the currently opened screens which includes both attached and detached Screen sessions.

Detach session

Ctrl+A  –d

This command can be used for detaching a current Screen session in order to re-attached in future.

Reattach session

$ screen –r screen_ID/screen_name

This command can be used for re-attaching a Screen session that was detached previously.

Switch between windows

Ctrl-a n

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

Ctrl+a "

It is used to list the opened bash windows.

Splitting horizontally

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.

Splitting vertically

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.

About the author

Karim Buzdar

Karim Buzdar

Karim Buzdar holds a degree in telecommunication engineering and holds several sysadmin certifications. As an IT engineer and technical author, he writes for various web sites. You can reach Karim on LinkedIn.