tmux is terminal multiplexer. More simply, using tmux, you can have multiple terminal sessions, or panes, within a singular window. Each pane is running its own independent terminal session.
Before getting into how to use tmux, it is important to note all commands in tmux are trigged by a prefix key followed by a command. The tmux prefix key is C-b
.
The C-
notation means press and hold the Ctrl
key.
Together C-b
means to press the Ctrl & b
keys at the same time.
-
Install tmux on a Personal Machine
Linux
Use the following Terminal command to install tmux (depending on your Linux OS):
sudo apt-get install tmux sudo yum install tmux sudo dnf -y install tmux
macOS
Use the following Terminal command to install tmux:
brew install tmux
-
Navigating tmux Panes & Windows
Launch tmux (Start a Session)
To launch tmux, open your terminal window and execute the following command:
tmux
Panes
Creating multiple panes in one window allows you to see what you're working on across multiple terminal sessions at the same time.
Managing Split Panes
Here is where you will begin to use your <prefix> + commands.
Create a Horizontal Split Pane (Left/Right)
prefix + %
(Press your prefix -
Ctrl + b
- then release and press %)Create a Vertical Split Pane (Top/Bottom)
prefix + "
Navigating Through the Panes
To navigate through the Panes, use your prefix + arrow keys.
prefix + up arrow prefix + down arrow prefix + left arrow prefix + right arrow
Closing Panes
Use the
exit
command to close a specific pane.To completely close the pane:
prefix + X
Windows
tmux also allows you to create multiple windows, or similar to having multiple virtual desktops!
Create a New Window
prefix + c
Renaming Your Window
If it helps you stay organized, you can rename your windows at anytime:
prefix + ,
You will be prompted at the bottom of the screen to rename the window.
Navigating your Windows
Go to Previous Window
prefix + p
Go to Next Window
prefix + n
Go to Specific Window
If you've created so many windows it becomes difficult to navigate with p and n alone, you can go to a specific window by going to the session number in your window's name in the status bar:
prefix + sessionnumber
Closing Windows
To close the current window:
prefix + &
Restart tmux
To kill all existing tmux sessions and start fresh:
tmux kill-server
-
Session Handling with tmux
One of the perks of using tmux is its ability to maintain sessions in the background. If you are done with your work for the day, you can keep the session alive in the background for later use.
Detach Sessions
Use the detach command to detach your current session so you can shutdown:
Detach All Windows
prefix + d
Detach Specific Window(s)
You can select specific windows to detach with:
prefix + D
Restart Detached Sessions
To view a list of the tmux sessions running in the background:
tmux ls
Use the attach command to get started on your session (where # is the session number):
tmux attach -t #