- It behaves like a Windows Manager for the terminal. When inside tmux, you can:
- Partition the tmux window into multiple “panes”, each would have its own command line.
- Run multiple tmux windows with the same session.
- Run multiple tmux sessions and switch between them, like virtual desktops.
- It allows multitasking inside the terminal (run multiple processes).
- It allows applications and processes to run in the background, even after closing the terminals. This is achieved by “detaching” a tmux session. When tmux is started again, the tmux session(s) can be re-attached and the running processes will not suffer any interruptions.
- It is scriptable, configurable, and ships with a powerful command system that allows to retrieve and manipulate information on its objects.
- It has a mature community-developed suite of tools to further enhance the user experience.
The key elements to understanding and using tmux effectively are centered around Sessions, Windows, and Panes (using the tmux terminology).
- Session – the entity that holds one or more Windows. Once tmux is started, it will have at least one session. Sessions are like Workspaces in Tiling Windows Managers, or VMs in Virtualbox.
- Window – the entity that holds “panes” and resides within a session. All sessions start with at least one Window open. Windows have layouts and can be split into “Panes”.
- Pane – is a pseudoterminal encapsulating the shell. A tmux Window can be split into panes, each is a terminal that can run applications or processes. Think of a Pane as a “terminal within a terminal.” When tmux is running, you will always have at least one pane open.
Installation and Basic Usage of tmux
sudo pacman -S tmux
To start using tmux, simply type tmux in the terminal and hit the enter key. Your screen should look something like the screenshot below. Notice the bright green status bar at the bottom of the screen. This is your visual indicator that you are in tmux environment now.
The default prefix key in tmux is
While holding down the
control key, press
To learn the default key sequences for common tmux operations, use the following cheat-sheet for quick reference:
It is very important to understand that we interact with tmux using commands. These commands are what tmux uses to set options, navigate panes, switch windows, and what have you.
There are multiple ways to sending commands to tmux:
- Keybindings (or keyboard shortcuts) – all keybindings must start with the prefix key (Ctrl + b by default).
- tmux commands sent from the shell – tmux must be started and all tmux commands follow this format: $ tmux <command>
- User -defined config file – if it exists, tmux reads the user config file when the server first starts. The default location for the tmux user config file is: ~/.tmux.config. The config file is a good place for settings or options that need to be persistent.
For example, let’s say you would like to show all sessions actively running after tmux starts. You can accomplish this by:
Ctrl + b and then press the key s
Or, from the shell, type the command:
$ tmux list-sessions