I don't know if you are like me. Every time I read an article or watch a video that features a tool that seems interesting, I can't help but search online to find out what it is, what it can do, and whether I can use it... I ask myself questions and then seek out the answers. Many times, if I don't understand its application or can't see its benefits, I pass it by. But if I happen to see it again, my curiosity returns and I restart the whole process.
I really like command-line tools (CLI) because of their utility. Instead of clicking, I just type. Additionally, their strength is most evident through their automation capabilities or allowing other programs to call them. Just by writing a function using spawn
in Node.js, I can interact with them. Moreover, CLI offers many features to increase my productivity.
Tmux is an application that embodies both of these factors. Tmux appears in many places online. I don't remember when I first came across this name, but it must have been a long time ago. I recall reading its documentation and understanding nothing at all. Watching usage guides on YouTube, they seemed to type commands swiftly, but I still didn't grasp anything. Many praised Tmux, and a lot of people used it. Yet, I felt helpless!
It wasn't until a while later when the CTO "demonstrated" some of Tmux's benefits to me. Wow! It really is powerful, and I had no idea all this time. I must say that thanks to him, I expanded my understanding. Therefore, today I would like to share it with you.
What is Tmux? Tmux is a terminal multiplexer. It allows you to easily switch between multiple programs in a single terminal, detach them (they still run in the background), and reattach them to another terminal 😆. Sounds bewildering, right? I don't understand it at all! No wonder I didn't get it back then.
To make it easier to visualize, imagine Tmux as an application. When installed on your machine, it creates a server and a client. The server manages the terminal windows, while the client provides commands (CLI) to interact with those terminals. Why is it so complicated? I just need to open a terminal window, and that's it!
The difference is that Tmux's server manages terminal windows, so it is not bound to any console. Multiple terminal sessions can be created within a single Tmux session. This means you can attach terminal sessions to any console. For example, you can have multiple terminal applications like the default Terminal of the operating system, iterm2, alacritty... you can switch Tmux sessions from one to another without much concern.
Tmux helps run background tasks without needing to keep the terminal window open. If you open a normal Terminal application, execute a running command, and accidentally exit, the command will vanish with it. But with Tmux, that's not the case. It keeps the task running in the background, as long as you don't intentionally close it.
Remember the Terminal screen? You can only view and interact with one working session in a single window. With Tmux, you can freely attach as many screens to that window as you like for easy monitoring. Moreover, if you logout and come back, the windows will still be there for you to continue working without having to reopen each one.
You can create numerous sessions, each containing many terminal screens, and easily navigate between them. Furthermore, you can share them with others because Tmux operates on a client-server model. As long as the client has access to the server, it's good to go.
Tmux also provides many advanced configuration options for personalizing, helping you optimize your own workflow.
Detailed installation instructions can be found at Installing | tmux Github. Since I use Mac, I installed it via brew
.
$ brew install tmux
After installation, to start a new session, use the command
$ tmux
You will immediately see a screen that looks just like the old one, the only difference being the green line at the bottom indicating that you are in a Tmux session. Try typing a command, like whoami
, then exit using the key combination Ctrl + b
followed by pressing d
. The green line disappears, indicating you have exited the Tmux session, but Tmux is still running in the background. Type tmux ls
to see the list of running sessions.
$ tmux ls
0: 1 windows (created Wed Feb 26 17:13:10 2025)
To access a session, type tmux attach -t 0
, where 0 is the session ID. Surprised? You can still see the traces of previous commands because Tmux keeps all your working sessions.
So how do you exit (kill) a session? There are a few ways. When inside a session, type tmux kill-session
or press the key combination Ctrl + d
. Alternatively, when outside the session, type tmux kill-session -t 0
, where 0 is the session ID.
Next, let's go to window management. To create a new window in a session, use the key combination Ctrl + b
then press c
. Immediately, you will see a new window created in the session. To switch between windows within the session, press the key combination Ctrl + b
then press p
(previous) or n
(next) accordingly. To close a window, type exit
.
Now, this part is interesting. Instead of creating new windows overlapping other windows, let's open additional windows within the same screen. To split the screen horizontally, use the key combination Ctrl + b
then type "
, and immediately you will see 2 input windows. To split the screen vertically, use the key combination Ctrl + b
then type %
. To move between screens, use the key combination Ctrl + b
followed by the corresponding arrow keys. To close a screen, press Ctrl + b
then type x
.
Tmux is a very powerful terminal multiplexer. You can create multiple sessions and keep them running in the background. The examples above are just a few to help you visualize how to use it. There are many more commands and features you need to explore. Please refer to the documentation or consult experts like GPT if necessary!
Do you use Tmux, and how are you setting it up or using it? Please share in the comments section below. Thank you.
References
5 profound lessons
Every product comes with stories. The success of others is an inspiration for many to follow. 5 lessons learned have changed me forever. How about you? Click now!
Subscribe to receive new article notifications
Comments (0)