What is Tmux: A Beginner's Guide

Last update: 25/09/2024

tmux

There is a command line tool for efficiently managing multiple sessions that is very popular in Unix environments, such as Linux or macOS. In this post we are going to explain What is Tmux. A small and useful guide for beginners.

Tmux is an abbreviation for Terminal Multiplexer. The definition of multiplexer when we talk about terminals is that of a program that allows a user to manage multiple virtual sessions within a single terminal. A resource that is especially practical when working with remote servers or when there is a need to run multiple commands simultaneously in different windows.

What is Tmux?

As a good terminal multiplexer, Tmux allows us split a single terminal session into multiple subwindows or panes within the terminal window itself. This way, we can allocate each of these small windows to run different programs or sessions shell. That, at least, was the goal of its creator, Nicholas Marriott, when it launched the first version of this multiplexer in 2007.

tmux
What is Tmux

Another interesting aspect is that it allows us Disconnect and reconnect to a session at any time without interrupting the processes that are running. This is very convenient when dealing with remote connections or long-term tasks.

These features make Tmux a software especially suited for certain kinds of tasks. For example, these:

  • Developments on remote servers.
  • Automation and monitoring tasks.
  • Efficient organization of multitasking work.
Exclusive content - Click Here  How to save email

The most common way to use Tmux is to creating multiple independent sessions. (one for development, another for monitoring, others to manage a server, etc.) that we can manage comfortably from a single monitor, being able to jump from one session to another easily and whenever we want.

How to install Tmux

install tmux

Now that we know what Tmux is, let's see how to install it on our computer. Installing Tmux is quite simple on Unix-based operating systems like macOS or Linux. We explain it below:

On macOS

To install Tmux on macOS Tmux we use the package manager Homebrew. These are the commands that we must use in the terminal:

  1. To install homebrew: «$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)«
  2. To Install Tmux: brew install tmux
  3. To verify installation: tmux -V

On Linux

If it is a system based on Arch Linux, it is possible to install Tmux from the official Arch repository. The method is even simpler:

  • Step 1: We open a terminal.
  • Step 2: Install Tmux using the package manager pacman:

On windows

Yes, it is also possible to install Tmux on Windows, although in this case the process is a bit more complex:

  1. The first step is install WSL (Windows Subsystem for Linux). To do this, you need to open PowerShell as administrator and run this command: wsl –install
  2. After We open source our Linux distribution within WSL and follow the instructions. The commands we need are these:
    • sudo apt update
    • sudo apt install tmux
  3. Finally, to start using Tmux we run this command: tmux

How to use Tmux

To start using Tmux, you first need to understand how it is organized. Each open session includes a group of windows. Each of these windows is equivalent to a terminal, so that a single session can have multiple windows. Finally, windows can also be divided into panels.

Exclusive content - Click Here  YouTube Video Song

what is tmux

A feature that allows us to use Tmux more quickly is the ability to use different keyboard shortcuts. These are the most common and useful:

  • Tmux prefix: ctrl + b
  • Create new window: Ctrl + b, then c
  • Split window (horizontally): Ctrl + b, then «
  • Split window (vertically): Ctrl + b, then %
  • Moving between panels: Ctrl + b, then we use the arrows.
  • Disconnect session: Ctrl + b, then d
  • Reconnect session: tmux attach
  • Close a panel or window: exit or Ctrl + d

In addition to this, Tmux offers us interesting customization optionsThis is possible by creating a configuration file to which each user can add code according to their tastes and preferences.

To create this file, run the following command: sudo touch ~/.tmux.conf

To add the configuration code, we need to open the file with a text editor and enter the settings we need. Here they go. Some examples that we can use:

Change the default prefix

If we wanted Ctrl+a instead of Ctrl+b, we would write the following:

# Change prefix from 'Ctrl+B' to 'Ctrl+A'

unbind Cb

set-option -g prefix Ca

bind-key Ca send-prefix

Using mouse mode

To bypass the default shortcuts and move windows and panels using the mouse. The command is:

set -g mouse on

Change the background color of the panel

If you want to change the background from black (default) to white, this would be the command to use:

set -g window-active-style bg=white

You will find many more tricks of this type on the web TMUXCheatSheet.

Exclusive content - Click Here  The best pages to download free books for your Kindle

In summary, everything we have explained here serves to conclude what Tmux is: a very powerful and practical tool, especially for developers and system administrators. In general, for any user who needs work efficiently with multiple terminals and simultaneous processes.