How to install and use tmux (terminal multiplexer)
With the terminal multiplexer tmux, you use multitasking with command lines from your chosen Linux distribution. tmux can be used to create, edit, separate or merge several sessions simultaneously in one terminal.
The operating system Linux is one of the most popular distributions alongside Windows and macOS. It’s open source and therefore free to use. Control and administration of one of the many Linux distributions such as Ubuntu, Debian or Linux Mint is often carried out using the command line or via the terminal and Linux commands. In order to use, manage and configure console sessions in a terminal simultaneously, terminal multiplexers such as GNU Screen or tmux are used.
- 99.9% uptime
- PHP 8.3 with JIT compiler
- SSL, DDoS protection, and backups
What is tmux?
The open-source terminal multiplexer tmux was developed by Nicholas Marriott and was first released in 2007. Functionally, tmux is similar to the terminal multiplexer GNU Screen, in that both give you the ability to work with multiple console windows in a terminal session and split them into separate panes while writing a shell script. In this way, you can even collaborate with others in parallel, ideally via Secure Shell (SSH) in remote sessions.
With tmux, you enter commands to control and edit your Linux distribution. These include, for example, commands for the assignment of directory rights with chmod or the “shutdown -h” command for a simple Linux shutdown. You can use tmux in Ubuntu, Debian, or other Linux distributions without any problems. In Windows tmux can only be used via WSL or WSL2 (Windows subsystem for Windows 2). With WSL2, you can also use Linux applications and Linux tools in Windows.
Are you looking for the right hosting partner for your Linux projects? Then consider using Linux hosting from IONOS with flexible rates, flexible scalable performance, SSL, DDoS protection and HTTP/2.
How to operate tmux
After being installed through official Linux package sources, tmux can easily be started via the terminal using the command “tmux”. The terminal multiplexer is operated through a typical terminal. The requirements for installing tmux are:
- Linux distribution or a Linux-based system
- User profile with root rights
- Access to terminal and command line commands / key shortcuts
The most important considerations when operating tmux are terminal sessions, windows and panels:
- Terminal sessions: In terminal sessions, you execute tasks and commands and operate your Linux distribution.
- Windows: If you want to execute specific tasks separately within a session, tmux allows you to work with several windows simultaneously in one session.
- Panes: You can also divide these windows into different areas (“panes”), e.g., to run error logs while you perform other tasks in the same window.
Commands and keyboard shortcuts are used to operate tmux, the most important of which are listed below.
tmux commands
Install tmux on Linux using the official Linux package manager:
apt-get install tmux
Install tmux on Ubuntu and Debian:
sudo apt-get install tmux
Start tmux
tmux
Start and name a new tmux session
tmux new -s [session name]
End a tmux session
exit
Reconnect to the last tmux session
tmux a -t [session name]
or
tmux a #
Show all tmux sessions (show session name and number of open windows)
tmux 1s
Adjusting panes with [Ctrl] + [B] + [:] and resize pane
If you divide a window into panes, you have the option of configuring the panes as you wish. To do so, first press the key combination [Ctrl] + [B] + [:]. You can now customize the panes using the following commands:
- Resize pane -D: Move the dividing line between panes downwards
- Resize pane -U: Move the dividing line between panes upwards
- Resize pane -R: Move the dividing line between panes to the right
- Resize pane -L: Move the dividing line between panes to the left
You can also move the dividing line around predefined cells as follows. However, this affects all panes in the window:
- Resize pane -U 10: Move the dividing line 10 cells upwards
- Resize pane -t 2 -R 5: Move the dividing line 5 cells to the right
Maximize and minimize pane (previously the key combination [Ctrl] + [B] + [:])
resize-pane -Z
Detach from existing session (with session name if necessary)
tmux detach
Attach to existing session (with session name if necessary)
tmux attach
tmux key combinations
As well as control and execution using commands and scripts, tmux is also operated by keyboard shortcuts. To initiate control using keyboard shortcuts, press [Ctrl] + [B]. All subsequent entries will produce the desired results. The most important shortcuts include:
Session commands:
- S: Display all sessions and switch between sessions
- $: Rename current session
- D: Detach existing session and move to background
- ?: Display currently active keyboard shortcuts (open help area)
Window commands:
- C: Create / open new window
- W: List all currently existing windows, switch between windows
- L: Switch to the last used window
- P: Switch to previous chronological window
- N: Switch to next chronological window
- ,: Rename current window
- &: Exit current window (confirm with “Y”)
- 1, 2, 3, (...): Jump to window number X
- [: Use scroll mode (scroll with arrow keys in current window)
Pane commands:
- X: Close current pane
- %: Split current pane vertically (second pane is created in the window)
- ": Split current pane horizontally (second pane is created in the window)
- Arrow keys (left, right, up, down): Navigate between panes
- H: Jump to left pane
- I: Jump to right pane
- J: Jump to bottom pane
- K: Jump to top pane
- Q: Show number of panes
- O: Navigate chronologically through all panes
- }: Swap current pane with the next one
- {: Swap current pane with the preceding one
- Space bar: Switch between the pane divisions
- !: Detach current pane and open it in a new window
Short tutorial on installing and using tmux
Follow these steps to install and use tmux:
Step 1: Install the terminal multiplexer from official Linux package sources using the install package command: apt-get install tmux
With Debian or Ubuntu, you’ll have to use the “sudo” add-on: sudo apt-get install tmux
Step 2: Start tmux by typing “tmux” into the terminal. When tmux starts, you’ll see a status display on the bottom of the window consisting of the host name (username@host-server), the time and the date. On the bottom left, you’ll see the name of the session (if named) and the number of windows in the following format “[0] 0:bash*”. The first window is named “0”. If there is a process running in the window, it is displayed after the 0 (e.g., “0:bash*”).
Step 3: Control tmux by using commands and keyboard shortcuts. Initiate each command or keyboard shortcut with [Ctrl] + [B] or, when configuring panes, [Ctrl] + [B] + [:] to get tmux’s attention.
Step 4: Start a new named session by using the command “tmux new -s”. After “-s”, enter the desired name of the session. If you want to start a session without a session name, simply type “tmux”.
Step 5: To end a session, enter the command “exit” or use the keyboard shortcut [Ctrl] + [D].
Step 6: To open a new window in the session, press [C]. To start a second session in parallel with the first, use the command “tmux new -s [session name].” again. The status display underneath shows which session you are currently in.
Step 7: If you want to divide a window into panes, press [%] for a vertically divided window or ["] for a horizontally divided window. Use the arrow keys to navigate between the panes.
Step 8: If you want to detach a running session but keep processes running, use the “tmux detach” command. The session and the running processes will continue to run in the background. To resume the session, use the “tmux attach” command to reconnect.
What can tmux be used for?
Just like the terminal multiplexer GNU Screen, tmux offers you the chance to work in multiple sessions and windows in a Linux distribution terminal, as well as to split and configure windows into multiple areas for multitasking.
This way, you can run parallel processes and programs and execute different tmux commands at the same time. Simultaneous remote sessions and collaborations with multiple users are also possible. You can also quit processes and sessions, move them to the background, and pick up where you left off later.
Do you need full virtualization and optimal VPS performance? Then use the vServer from IONOS with 100% SSD SAN storage for demanding projects, with scalable and dedicated resources and optional Plesk web hosting.
How tmux differs from GNU Screen
At first glance, GNU Screen and tmux work in exactly the same way and offer the same important functions. For example, you initiate commands and keyboard shortcuts in GNU Screen with [Ctrl] + [A] instead of [Ctrl] + [B]. One major difference, however, is that GNU Screen does not automatically display a status indicator with the name of the current session at the bottom of the window. If you want a status display in GNU Screen, you have to configure it manually.
The uncomplicated naming and renaming of sessions and windows also makes it easier to keep track of and navigate between windows and sessions in tmux. In addition, unlike GNU Screen, there’s no risk of losing a window completely if you detach it and move it to the background in tmux. Windows can easily be retrieved using a command line command, or an overview of all current windows can be accessed.
Use the scalable computing power of virtual machines for a powerful virtual infrastructure. The cloud server from IONOS offers 100% dedicated resources, root access, cloud panel and secure data centers for your project.
Is tmux worth it?
Whether it’s the renaming of windows and sessions or the helpful status and session indicators at the bottom of the window, many users find tmux clearer and more user-friendly than GNU Screen. If you work with several processes and programs in the terminal at the same time and rely on simple, efficient multitasking, tmux will prove to be a useful and worthwhile terminal multiplexer. And a free one at that.