In this blog, I will explain why many programmers say that they use Tmux rather than a Linux terminal. So let’s get started with the blog and know the power of Tmux.
Table of Contents
Introduction to Tmux
- In Tmux, users can move between numerous terminal sessions quickly by using keyboard shortcuts or by clicking on the tabs that correspond to each session. This enables users to multiplex multiple terminal sessions within a single terminal window or console.
- Users don’t have to switch between separate terminal windows while using tmux to retain numerous open terminal windows, each running a distinct application.
- The full form of Tmux is Terminal Multiplexer.
Features
- Tmux offers a mechanism to maintain terminal sessions even when the underlying terminal window is closed. This means that users can disconnect from a tmux session, then reconnect later and resume exactly where they left off, with all the same applications and terminal windows open and available.
- Tmux supports split-screen functionality, which enables users to view multiple terminal windows within a single tmux session.
- These windows can be divided into panes, which can be resized and rearranged as needed. This provides a convenient way to manage multiple terminal windows, allowing users to see multiple applications at the same time, without having to switch between them.
- Additionally, tmux supports copying and pasting text across different windows and panes. It also offers a variety of customization options, such as the ability to establish unique color schemes, set keyboard shortcuts, and rearrange windows and panes.
- Tmux’s ability to be highly adaptable and tailored to each user’s unique requirements is one of its main features. Because of this, it provides the perfect tool for power users, system administrators, and developers who can utilize it to improve productivity.
Advantages
A) Session persistence
Tmux allows you to keep terminal sessions running in the background, even after disconnecting from the server.
B) Window and panes management
Tmux allows you to divide your terminal window into multiple panes and switch between them easily. You can also create new windows to run separate applications.
C) Copy and paste
Tmux offers a straightforward method for copying and pasting text inside of a terminal session without using mouse instructions.
D) Session sharing
Tmux makes it simple to collaborate on projects by allowing many people to log in to the same terminal session.
E) Customizability
The appearance and behavior of your terminal environment can be configured using a wide range of Tmux parameters.
Disadvantages
A) Steep learning curve
Tmux has a lot of features and can be difficult to learn and master.
B) Limited mouse support
Tmux does offer mouse-based navigation and selection, but its interface is less user-friendly than that of other terminal multiplexers.
C) Complex configuration
Tmux has a lot of configuration options, but finding the right set of options and customizing Tmux to your needs can be a challenge.
D) Lack of integration with other tools
Tmux’s lack of strong tool and program integration compared to certain other terminal multiplexers can make using it less seamless.
E) Limited customization
While Tmux is highly configurable, the level of customization is limited compared to other terminal multiplexers.
Note: Tmux is a powerful tool, and these disadvantages should be weighed against its advantages before deciding whether or not to use it.
Getting Started with Tmux
A) Installation of Tmux in the System
Installation of Tmux is very simple and straightforward on many operating systems, and there is nothing to worry about.
For Linux or any Linux distribution ( Ubuntu, WSL, and derivatives ):
$ sudo apt-get install tmux
For Mac:
$ brew install tmux
B) Check the version
After installing Tmux, we have to check whether Tmux is properly installed in our system. Type the command.
$ tmux -V
tmux 3.0a
The above command shows that in my system version 3.0a of Tmux is installed. If you get an error means there is some problem that occurred while installing the Tmux in your system.
c) Session
Tmux is a terminal multiplexer that allows you to run multiple terminal sessions within a single terminal window. Tmux sessions are very useful when you want to switch between different terminal sessions quickly.
1) Creating a new Session
To start a new tmux session, you can simply open a terminal window and type the following command:
tmux new-session -s mysession
$ tmux new-session -s first_session
![What is Tmux? | Introduction to Tmux 2 First Session in Tmux](https://binfintech.com/wp-content/uploads/2023/03/first_session_tmux.png)
From the above image, you can see a green line that tells the specific things:
[firs_sess] -> It is the name of the session i.e, first_session.
0 -> Number of the window
bash -> Name of the window.
* indicates that you are working in the current window.
2) Deattach from the Session
Deattaching the session does not mean that you are killing the session, it means that you are just leaving that session for a temporary period of time and you have not lost that session, you can enter that session whenever you want by attaching the session.
Just press the Ctrl + b + d key.
3) Attach the session
Attaching the session means that you can check or enter the session terminal where you have left off and check what the last command you have typed.
Syntax:
$ tmux attach-session -t mysession
$ tmux attach-session -t first_session
4) List all the session
$ tmux new -s Docker
$ tmux ls
Docker: 1 windows (created Wed Mar 8 02:27:33 2023)
first_session: 2 windows (created Wed Mar 8 02:24:45 2023)
As we know, we created our first session with the name “first_session”, and now we have to create a new session “Docker” with the help of the tmux new -s Docker command.
Now to check how many sessions we have created, use the tmux ls command
Docker: 1 windows -> It means that the name of the session is Docker containing 1 windows in it.
first_session: 2 windows -> It means that the name of the session is first_session containing 1 windows in it.
5) Rename the Session
Now, let’s rename our “first_session” session to the “git” session name.
Syntax:
$ tmux rename-session -t prev_session new_session
$ tmux rename-session -t first_session git
$ tmux ls
Docker: 1 windows (created Wed Mar 8 02:27:33 2023)
git: 2 windows (created Wed Mar 8 02:24:45 2023)
From the above output code, we can clearly see that we have successfully changed the session name from “first_session” to “git”.
6) Kill the session
Killing the session means that you are closing the session.
$ tmux kill-session -t Docker
$ tmux ls
git: 2 windows (created Wed Mar 8 02:24:45 2023)
Here, we have successfully deleted the session, Docker, now there is only one session which is git.
d) Panes
In tmux, a pane is a section of the terminal window that is divided into multiple sections.
Each pane can run a separate command or application, allowing you to multitask within the same terminal window.
Overall, panes are a powerful feature of tmux that allows you to easily manage multiple tasks within the same terminal window.
Before running this command, you should be in the tmux terminal
Here are some basic commands for working with panes in tmux:
Ctrl-b %
: Split the current pane vertically.Ctrl-b "
: Split the current pane horizontally.Ctrl-b <arrow keys>
: Navigate between panes.Ctrl-b z
: Toggle zoom mode for the current pane.Ctrl-b x
: Kill the current pane.
e) Windows
windows in tmux are independent of the shell windows in your terminal. You can have multiple windows open in tmux, each with its own shell session running different commands or programs. This can be useful for organizing your work and switching between tasks quickly.
A) Starting a new window with the new session
Here, you are creating a new session and along with that, you are creating a new window in that session.
Note: The windows are always inside the session.
$ tmux new -s new_session -n new_window
tmux new -s first_session -n Docker
This will create a new session “first_session” and add the window with the Docker name.
B) Starting a new window already a present session
Now, suppose you want to add a new window “bash” in the “first_session”.
Just press Ctrl + b + c key
It will automatically add the new window. To check whether the new window is added in that session or not, just type the tmux ls command.
$tmux ls
first_session: 2 windows (created Wed Mar 8 03:06:28 2023)
You can clearly see there are 2 windows present in the “first_session”.
C) Renaming the window
First, go to that session by using the attach command and then press the “Ctrl + b +,” key and rewrite the name of the window.
D) Switching between the windows
Switching between the windows in the session is very easy, just press Ctrl + b + window_number. And you will know whether you are working in the correct window or not. Just see the asterisk mark below the terminal.
![What is Tmux? | Introduction to Tmux 3 switching-between-the-windows](https://binfintech.com/wp-content/uploads/2023/03/switching-between-the-winows.png)
From the above image, you can see a green line that tells the specific things:
[firs_sess] -> It is the name of the session i.e, first_session.
0 -> Number of the window
bash -> Name of the window.
* indicates that you are working in the current window.
From the above image, we can clearly see there are three windows first one is Docker, the second one is bash and the third is python. Currently, you are working on the Docker command because there is an asterisk mark.
E) Exit the window
Just type the exit command, and it will kill that window in that session.
CheatSheet
If you want to learn more about Tmux commands shortcuts. Click the below link
FAQ
In Tmux, users can move between numerous terminal sessions quickly by using keyboard shortcuts or by clicking on the tabs that correspond to each session. This enables users to multiplex multiple terminal sessions within a single terminal window or console.
Users don’t have to switch between separate terminal windows while using tmux to retain numerous open terminal windows, each running a distinct application.
Tmux offers a mechanism to maintain terminal sessions even when the underlying terminal window is closed. This means that users can disconnect from a tmux session, then reconnect later and resume exactly where they left off, with all the same applications and terminal windows open and available.
Tmux supports split-screen functionality, which enables users to view multiple terminal windows within a single tmux session.
Tmux is a terminal multiplexer that allows you to run multiple terminal sessions within a single terminal window. Tmux sessions are very useful when you want to switch between different terminal sessions quickly.
Use the command:
$ tmux new -s session_name