Tmux is a rather popular terminal multiplexer that serves as an alternative to the GNU Screen. It allows you to start a session and then open multiple windows inside said session which each window occupying the entire screen and can be split into multiple rectangular panes.
It allows users to switch between multiple programs in one terminal and detach or reattach them at will to a different terminal. Tmux sessions are persistent, which means that programs will continue running even if you get disconnected.
Also read: Mint vs Ubuntu: Linux distro comparison
How to install Tmux?
There are several ways you can install Tmux on different Linux distros.
- Ubuntu/Debian: sudo apt install tmux
- CentOS/Fedora: sudo yum install tmux
- macOS: brew install tmux
Once you’ve installed Tmux on your system, you can launch a session by typing tmux in the terminal and pressing enter. You’ll notice a status line at the bottom of the screen which shows information about the current session.
All commands in Tmux have a Ctrl+b prefix. To get a complete list of commands, type Ctril+b ? and hit enter.
Also read: How to remove a Directory in Linux?
How to create named Tmux sessions?
Tmux sessions are named numerically by default. However, you can change this and name each session to your liking. This is extremely helpful when you’re dealing with multiple sessions at once.
tmux new -s sessionName
The above command will launch a new Tmux session with the specified name.
How to detach and reattach from Tmux session?
To detach a Tmux session, type Ctrl+b d and hit enter. The program, if any, running in the session will continue running even after you detach from the session.
To get a list of running Tmux sessions, type tmux ls in the terminal, and you’ll get all the information you need about all the currently running Tmux sessions.
Now to attach to a session, use the following command.
tmux attach-session -t sessionName
Tmux windows and panes
By default, Tmux creates a single window containing a shell. To create a new window with a shell, type Ctrl+b c and the first available number from zero to nine will be assigned to said window. You’ll be able to see a list of all windows at the bottom of the screen.
Here are some of the most common Tmux commands for managing windows and panes.
|Ctrl+b c||Creates a new window with a shell|
|Ctrl+b w||Chooses a window from a list|
|Ctrl+b 0||Switch to window 0, or any other specified number|
|Ctrl+b ,||Renames the current window|
|Ctrl+b %||Splits the current pane horizontally|
|Ctrl+b “||Splits the current pane vertically|
|Ctrl+b o||Move on to the next pane|
|Ctrl+b ;||Toggle between the current and previous pane|
|Ctrl+b x||Closes the current working pane|
By default, Tmux reads its configuration parameters from the ~/.tmux.conf, provided the file is present. You can modify this file to add colours, improve buffers, customise status lines and whatnot.
Also read: How to check the list of users in Linux?
Basic Tmux usage
When you’re just starting out with Tmux, here’s the process you should follow.
- Type tmux new -s sessionName to start a new session.
- Run the desired program/programs.
- Use Ctrl+b d to detach from the session if needed.
- Reattach to the session as and when required using the tmux attach-session -t sessionName command.
Also read: How to change password in Linux?