Getting started with tmux
Tmux is a terminal multiplexer. It allows you to work with multiple terminal sessions at once.
It is easy to install, and there are many guides already out there, so I won't cover it in this blog post.
So, let us start with the basics.
tmux server (programm) > session > window > pane
The tmux server starts after running tmux. You can work on the attached sessions or detach them so they run in the background. Every server can have multiple sessions, every session can have multiple windows, and we can split a window into multiple panes. The pane is a normal terminal window at the end.
There are a lot of use cases for it. Tmux makes is easy to separate projects in different windows or sessions.
The prefix or lead and meta-key
The default prefix (or sometimes called 'lead') is
C-b) and it is usually the start of a tmux shortcut or to use a tmux command. When you see something like:
b, and then
c. I prefer
s for example. I'll explain how to change it in the next section.
As a side note: you'll find some shortcuts with an
M in them. This is the
meta-key. It is
ALT for Linux, I think
CMD in MacOS, and sometimes even
meta-key is rarely used, but worth looking it up.
The config file
You can temporarily change your tmux config by entering the setting:
:set -g prefix C-s
This would change the
Prefix as we described it before. If you want to make changes permanently, edit the config file. On Linux, the config file is usually in the home directory of the user
~/.tmux.conf. If there is no config file, simply create it, and restart tmux - or reload it (will show in the end of this section). Just put
set -g prefix C-s into the config file and tmux will use it after the restart.
There are many ways to customize tmux. Some examples: Vim-like bindings for pane movements, enabling mouse support, setting keyboard shortcuts, and so on.
The easiest way to reload the config file after changes is to use the following tmux command:
:source-file ~/.tmux.conf (change the path accordingly).
Working with panes
As mentioned before, you can split a window in multiple panes. You can split the window vertically or horizontally as you wish and change it as much as you want. I won't cover everything in this post, but I'll show you the basics.
- Split horizontally:
- Split vertically:
- Move to another pane:
- Convert the current pane into a new window:
- Close current pane:
There are shortcuts for resizing, moving panes around, and so on, but those aren't that important for this primer.
Side note: I just wrote a separate post about sending input to all panes within a window. Feel free to check it out here.
Working with windows
I prefer to separate my projects with windows instead of sessions, but that is my personal preference.
- Create a new window:
- Rename current window:
- Close current window:
- Switch to next window:
- Switch to previous window:
- Switch to window by number:
Working with sessions
Let me start with a shortcut that I just learned recently.
This gives you a quick overview of all sessions and windows and lets you switch quickly.
- Show all sessions:
- Create new session:
tmux new -s new-session
:new -s new-session
- Rename session:
- Detach session (will be active in the background):
- Close a session:
tmux kill-session -t old-session
- Attach session:
tmux attach -t old-session
- Move to next session:
- Move to previous session:
This post hopefully will help you to get started with tmux. I'll cover more topics and features of tmux in the future.
Any notes or questions? - Feel free to reach out.
E-Mail hello @itta vern. com
- 13.03.2023 My Offsite Backup - March 2023
- 10.03.2023 Getting started with iperf3 - Network Troubleshooting
- 05.03.2023 ICMP echo requests on Linux and Windows - Reference Guide
- 14.02.2023 Simulate an unreliable network connection with tc and netem on Linux
- 08.02.2023 Detecting Rogue DHCP Server