When we are developing on the terminal, managing multiple processes and tasks efficiently is crucial; this is where tmux comes into play. The tmux software is a powerful tool that allows us to split the terminal into multiple panes and windows, making it easier to multitask, monitor processes, and organize the work.
Before we start using tmux, we need to install it on our terminal. The tmux software is available for most Unix-like operating systems, including Linux and macOS, and can be installed using package managers like apt
, brew
, or yum
. Install it on the terminal below by entering the following command:
apt-get install -y tmux
Once the installation is complete, enter the following command to run tmux:
tmux
Notice that the regular terminal interface gets replaced with a different interface. We can enter the exit
command on the tmux software to return to the original terminal.
A significant feature that tmux offers is running multiple terminal windows within the same or different sessions in parallel. Once tmux is deployed on our terminal, we can now look at how we can utilize this feature. First, we need to create two new windows within the same session. Use the following command two times, replacing "Window Name"
with any name of your choice, to create two new windows in tmux:
tmux new-window -n "Window Name"
Next, we split the terminal horizontally using the following command:
tmux split-window -h
Once we have the two terminals running side by side, we can interact with the desired window that we created in the first step by using the following command:
tmux select-window -t Window Name
Replace the Window Name
command with the desired window. We now have two different windows running within the same session, and we can monitor each window in parallel.
The tmux terminal is driven primarily by keyboard shortcuts, called key bindings. The default prefix key for most tmux commands is “Control + B” on windows and “Command + B” on macOS. Here are a few essential key bindings you will need to know:
The “Command + B + C” key bindings create a new window.
The “Command + B + ,” key bindings rename the current window.
The “Command + B + %” key bindings split the current window vertically.
The “Command + B + " ” key bindings split the current window horizontally.
The “Command + B + N” key bindings switch to the next window.
The “Command + B + P” key bindings switch to the previous window.
The “Command + B + D” key bindings detach from the current session (leave it running in the background).
Note: These key bindings will not work on the terminal on Educative’s platform; they will only work on the terminal available on your machine. Click the “Show Hint” button below to see how you can perform some of them using command line codes.
The tmux software is a versatile tool for anyone working extensively with terminals. It provides a rich set of features for managing terminal sessions efficiently, improving productivity, and customizing the development environment to suit your needs. Once you are familiar with the basics of tmux, you can move on to learning more of its advanced features to better boost your productivity.