What is tmux?
tmux (not Tmux) is a command-line utility that allows to create and manage multiple terminals from a single screen. In technical terms, it is known as a terminal multiplexer.
How to use it?
On macOS, install tmux using Homebrew
brew install tmux
Based on your OS, you can install it using package managers like
yum, etc. Visit tmux on GitHub for installation instructions for other operating systems.
To get into tmux, type:
You will see the tmux screen with the highlighted green/lime coloured bar at the bottom. The left side of the highlighted bar indicates the list of your opened windows.
Right now, we have just one window which is indicated by
|zsh||window name (editable)|
To create a new vertical pane, press
shift+5). In tmux world,
ctrl+b is the prefix.
To create a new horizontal pane, press
To switch between panes, press
up/right/down/left arrow key.
To create a new window, press
As you can see, a new window was created which is indicated by
The reason both windows have
zsh as window name is because I am using
zsh shell. It would have been
fish or any other shell if you were using one of them.
Currently, the active window is window
1. If you want to switch back to window
There are other ways to navigate among windows:
l-> navigate to last window
p-> navigate to previous window
n-> navigate to next window
To rename a particular window, say
,. Let's rename it to react.
To rename window labelled
1, first switch to it using
1 and then press
,. Let's rename it to angular.
To close down a window, just type
tmux handles terminal processes in the form of sessions.
Whenever you start tmux by typing
tmux in the terminal, you are actually starting a new tmux session. A tmux session preserves your state i.e. whatever process is running within that session.
Suppose you lose a connection to a server that was connected through SSH using tmux for whatever reason. The next step is to ssh back into that server and attach to the tmux session. At this point, you will be exactly were you left off. All the processes that were running before you lost the connection would have been intact.
To detach from a session that you are working on, press
d. As you might have guessed,
d stands for detached.
Now, you are back to your normal terminal. To view all the tmux sessions running in the background, type:
|1||number of windows opened|
To re-attach to session labelled
tmux attach -t 0
Let's output some data to demonstrate how it preserves the sate.
fortune | cowsay -f turtle | lolcat
Detach from the session and then re-attach to it using the aforementioned commands. You will find that the state is preserved.
Now, let's rename the session labelled
tmux rename-session -t 0 'todo-app'
To create a new session named
tmux new -s git
Let's view all the sessions that are currently running after detaching from the
Keep in mind that these sessions will be preserved until the system reboots.
git session, type:
tmux kill-session -t git
tmux can do a lot more. In my next post on tmux, I will share its advanced usages.