Tmux is a Linux program that enables terminal window multitasking. It is an acronym for Terminal Multiplexing and is based on the concept of sessions. Tmux may be disconnected from a screen and run in the background before being reattached.
Tmux is a terminal multiplexer that may be used in place of the GNU screen. You can establish a Tmux session and then open many windows within it. Each window takes up the whole screen and can be divided into rectangular panes. Users can initiate a process, switch to another, detach from and reconnect to a current process.
Tmux enables easy switching between many applications in a single terminal and detaching and reattaching them to a separate terminal. Tmux sessions are persistent, which means that they will continue to function even if you are disconnected.
As a popular multiplexer, Tmux has plenty of valuable options. It allows you to run many programs in parallel and seamlessly transition between them. Consider using a multiplexer if you’re continuously switching between terminals and can’t find the appropriate window when needed.
How to install and set up Tmux on Linux?
Before we look at the installation processes, ensure you have all the prerequisites mentioned herein:
- A Linux-based operating system
- A user account that has sudo or root access
- Terminal window/command-line access
When Tmux is launched, a new session with a single window is created and displayed on the screen. At the bottom of the screen, a status line indicates information about the current session and may be used to input interactive instructions. This article will walk you through installing and configuring Tmux on Linux workstations. Open a terminal and follow the installation instructions for your system.
Installing Tmux on Ubuntu / Debian
On your terminal, execute the following line of code:
sudo apt-get install tmux
Install Tmux on Arch Linux
sudo pacman -S tmux –noconfirm
Install Tmux on Fedora
sudo dnf -y install tmux
Install Tmux on CentOS
sudo yum -y install tmux
Install Tmux on RedHat
sudo yum install tmux
Install Tmux on macOS
brew install tmux
Once the installation phase is complete, open a terminal window and type Tmux to begin a new Tmux session. This command creates a new session within a window and launches the shell. The bottom status bar contains information regarding the current session.
Note: You can check the version of your Tmux by executing the command below. Alternatively, this command helps you check whether Tmux has been successfully installed on your Linux distro.
Tmux’s default key combination is: “Ctrl + B.”
How to use Tmux
Tmux incorporates concepts such as sessions, windows, panes, and hotkeys. As a result, novices frequently find it daunting at first. However, you’ll feel far more productive after you’ve mastered it.
A Tmux session denotes the scope of the task at hand. Windows enables users to execute a variety of functions inside a single session. On the other hand, Panes will allow you to work with distinct perspectives within a single window.
All of them may be controlled by Tmux hotkeys, composed of the Tmux prefix followed by a specified key. “Ctrl + B” is the default prefix.
How to manage Tmux panes
When panes are used, things become incredibly fascinating. Panes are essentially virtual terminals that operate within a window. They enable us to operate several terminal sessions from a single Tmux window.
In Tmux, you can build horizontal and vertical panels. Typing “Ctrl + B” splits the view horizontally.
This will divide the current window horizontally and open a new terminal in the newly created window. To open a vertical pane, use “Ctrl + B %.”
Note: To launch or split the screen horizontally using the “Ctrl+B %” shortcut, what you ought to do is first press “Ctrl+B” simultaneously on your keyboard. Nothing will happen, but don’t worry. Proceed and press “Shift+5” simultaneously for percentage, and the screen will be split. This is how you will use the other commands throughout Tmux. First, press the “Ctrl+B” combination followed by the key in question.
You may build both horizontal and vertical panes concurrently. To flip between panes, use the hotkey “Ctrl + B o.”
By toggling the pane zoom, users may conceal all other panes. This function comes in helpful when you need to concentrate on a single activity. Toggling panes are accomplished by pressing “Ctrl + B z.” Use the hotkey Ctrl + B x to close the current pane. To kill the pane, you must accept the prompt by typing “Y” on your keyboard, as shown below:
Below are some key commands to resize the Tmux panes:
- Resize-pane -D — Resizes the pane’s borderline downward.
- Resize-pane -U — Adjusts the pane’s borderline upward.
- Resize-pane -R – Resizes the pane’s borderline to the right.
- Resize-pane -L – Shifts the pane’s borderline to the left.
- Resize-pane -U 10 — Resizes the window by ten cells.
- Resize-pane –t 2 –R 5 – Shifts the boundary line to the right by five cells.
How to manage Tmux sessions
Tmux is capable of managing many sessions concurrently. This enables developers to move between many projects quickly. Additionally, you may create new sessions at any moment.
tmux new -s foss-session
The above command initiates the creation of a new session termed foss-session. Additionally, you may create sessions from an existing running Tmux instance. Start the Tmux interpreter and type the prefix accompanied by a colon, or “Ctrl + B:” for the default prefix.
The command will start a new Tmux interpreter in which we may enter command line arguments. To begin a new session, type the following.
:new -s foss-session
To display all active sessions, use “Ctrl + B s.” You may switch to a different session by selecting it and hitting Enter.
You can disconnect from any session, and Tmux will continue to run the process. To disconnect the current session, type :detach in the Tmux interpreter or press “Ctrl +B d.”
To reconnect to the previous session, run the following command.
You may connect to a specific Tmux session by supplying the session name. To accomplish this, use the -t option.
tmux attach -t foss-session
Use the kill-session statement to terminate a Tmux session.
tmux kill-session -t foss-session
Tmux window management
Tmux windows take up the entirety of the screen and can be divided into many panes. Each of these panels will function independently as a pseudo-terminal. “Ctrl + B c” can open a new Tmux window.
The following list lists the most often used Tmux actions and commands while working with Tmux windows.
Create a new window:
Switch between windows:
Ctrl-b [0-9] or Ctrl-b Arrows
Split windows vertically:
Destroy Tmux window:
Split windows horizontally:
Using and configuring Tmux
Tmux, like the majority of Linux programs, is extensively customizable. To make modifications, edit the tmux.conf file. By default, your system may lack a tmux.conf file. To generate custom modifications for a single user, add a file named /.tmux.conf in the user’s home directory. Create the file /etc/tmux.conf in the system directory to make system-wide modifications.
Almost every feature of your tmux system may be configured. However, we recommend that you begin with the fundamentals and work your way up to more complicated alternatives.
The /.tmux.conf file is used to configure Tmux. Edit this file using your preferred Linux text editor.
We may modify the base index of panes and windows from 0 to 1. It is intuitive for those who are unfamiliar with zero-based indices.
set -g base-index 1 #Window labelling starts from 1 set -g pane-base-index 1 #Pane labelling starts from 1
In the tmux.conf file, you may change the prefix from “Ctrl + B to Ctrl + A.”
set -g prefix C-a unbind C-b
There are no mouse functions built into Tmux because it is a terminal-based utility. Fortunately, adding the following line to your Tmux setup will allow you to enable mouse functionality.
set -g mouse on
You may now start utilizing Tmux in various ways, such as establishing numerous windows in a single Tmux session, generating new panes, navigating between windows, detaching and rejoining sessions, and personalizing your Tmux instance using the.tmux.conf file.