In this tutorial, we’ll show you how to use , a tool that allows you to split a terminal window into multiple ones. Thus, in a single window you can have several instances of the terminal open, similar to the Byobu. This tool is ideal for speeding up terminal tasks, especially if you are a system administrator and need to manage several terminals in one.
How to install Tmux on Ubuntu or Debian
Tmux is a tool that is part of the official Debian and Ubuntu repositories. Which makes it incredibly easy to install! To do this, APT is used, which is the Debian and Ubuntu package manager. With this package manager you will be able to install, uninstall and update packages without worrying about dependencies. You will first need to access your server via SSH. Consult our if you have problems with this step.
Installing this tool will require administrator privileges, so we suggest adding sudo to the command.
Run this command to install the tool:
sudo apt install tmux
Next, it is a good idea to confirm the installed version. We can do it with the following command:
tmux -V
At this point Tmux will be properly installed and ready to use.
Getting started with Tmux
Tmux is a session-based application. That is, once you run the tool a new session is opened. In each session there can be several terminals, since Tmux is a terminal multiplexer.
So, to start using this tool you will need to open a new session. You do this with the command:
tmux new
Once you log in, you will see the same terminal as always, except there will be a green bar at the bottom. This bar indicates the active session and confirms that you are using Tmux.
It is also possible to give the session a name. To do so you can type the following command when opening a new session:
tmux new -s
The most important utility of Tmux is that it allows different instances of terminals in a single window. In other words, several terminals in the same session. In addition, you will be able to access them quickly and easily from the keyboard.
Now, to end a session you must write the following command:
exit
Using prefixes to control Tmux
Tmux is based on commands that perform a specific task. However, to run these commands, a prefix must first be used. The prefix tells Tmux that a command will be executed. By default, the prefix is CTRL + B.
So the correct way to structure a command in Tmux is:
That is, you have to press the keys CTRL+B and then the command. For example, to create a new session, the command would be C. So, to create a new session, you have to press CTRL+B and then C – CTRL+B, C.
Some useful commands
Another great feature of Tmux is that you can “save” a specific session. For example, if you are using htop and you use the detach command, when you run Tmux again you will see that the process is still running. This is very useful for working with commands that take a long time to execute, such as backups.
So, you can start a new session by typing this command on the command line:
tmux new
In that new session run htop. Htop is a tool that allows you to monitor system resources.
Then use the detach command. So, first enter the prefix by pressing CTRL+B and then the command D. You will see a message in the terminal.
You will now need to go back to the “attached” session. To do this, run the following command in the terminal:
tmux attach -t
If you haven’t given the session a name use the value 0. In this case the command will look like this:
tmux attach -t 0
And you will return to your previous session.
It is possible to start multiple sessions with the command C. To navigate between them use the assigned name or the identifier number. For example, the first session you created from the regular terminal would be 0. If you create another session, this will correspond to the number 1.
CTRL+B, 1
You can see what the current session is in the green bar at the bottom of the window.
You can see how many Tmux sessions are open with the following command:
tmux ls
Management panels
Let’s learn how to manipulate terminal panels. You can split a window horizontally, with the command
In this case it would be: CTRL+B, “.
And to do the same but vertically: CTRL+B,%.
To switch between panels, we can use the command – CTRL+B, arrow key.
You can also navigate through each of the panels. If you want to close only one you must press – CTRL+D.
Tmux Cheat Sheet, reference commands for Tmux
Finally, we want to share with you a command sheet to use as a reference:
sessions
Start a new session:
tmux
Start a new session and give it a name:
tmux new -s
Start another session in parallel:
tmux attach #
If the tmux session has a name:
tmux attach -t
List all tmux sessions:
tmux ls
Exit Tmux:
exit
window management
New window
Panel management
Split panes vertically
conclusion
As you have seen, Tmux is an extremely important tool that helps to use the terminal efficiently.
The management of this tool is done through commands, accessing from your . In this Tmux tutorial you have learned the most basic and useful for daily work. If you want to know more about this command, we recommend that you consult its official documentation.
Additional reading:
Deyi is a digital marketing enthusiast, with a background in web design, content creation, copywriting, and SEO. She is part of ‘s SEO & Localization team. In her free time, she likes to develop projects, read a book or watch a good movie.