Introduction
In the world of system management and software development, working with multiple terminals simultaneously can significantly improve productivity. The tmux command in Linux is presented as a powerful solution for multiplexing terminal sessions, allowing to divide the screen into panels, create windows and keep sessions active even after closing the SSH client. This article explores from basic concepts to advanced techniques to make the most of tmux.
What's tmux?
Tmux (multiplexer terminal) is a program that allows access to several terminals within a single window. It works as a server that manages sessions, each consisting of one or more windows, and each window can be divided into panels. This architecture facilitates the organization of the work, as you can have a panel to edit code, another to see logs and a third to run commands, all without losing the context.
Installation
In most Linux distributions, tmux is available in official repositories. In Ubuntu or Debian, just run:
sudo apt update && sudo apt install tmuxsudo dnf install tmuxin Fedorasudo pacman -S tmuxin Arch Linux
After installation, you can start tmux by simply typingtmuxAt the terminal. If you want it to start automatically when opening a new session, add the lineif [ -z "$TMUX" ]; then tmux; fiat the end of your file~/.bashrcor~/.zshrc.
Basic Command
The default prefix of tmux isCtrl + b. After pressing the prefix, you can type different commands:
- Ctrl + b ccreate a new window.
- Ctrl + b,allows to rename the current window.
- Ctrl + b nandCtrl + b pchange to the next or previous window.
- Ctrl + b%divide the current panel into two vertical panels.
- Ctrl + b 'divide the current panel into two horizontal panels.
- Ctrl + b arrow(left, right, up, down) moves the focus between panels.
- Ctrl + b zalter the zoom mode, extending the active panel to full screen.
These shortcuts form the basis for browsing and organizing your working environment within tmux.
Panel and window management
In addition to keyboard shortcuts, tmux allows you to run commands directly from the prefix command line. For example,Ctrl + b:open the tmux prompt where you can write:
split-window -hto split vertically.split-window -vto divide horizontally.resize-pane -L 5to reduce the width of the panel to the left in 5 cells.select-layout even-horizontalto distribute the panels evenly.
You can create sessions named withtmux new -s nombre_sesion, which is useful when working on several projects simultaneously. Each session maintains its own set of windows and panels, isolated from the rest.
Meetings and displacement
One of the most valued features of tmux is the ability to disconnect and reconnect a session without losing the status. To disconnect (detach) a session, pressCtrl + b d. To list all active sessions, usetmux ls. To reconnect (attack) to a specific session, runtmux attach -t nombre_sesion. You can even share a session with another user by usingtmux attach -t nombre_sesion -c /ruta/compartida, as long as we have the right permits.
The movement within a panel is done withCtrl + b [, which goes into copy mode. From there, you can use the arrows or the keysPageUp/PageDownto navigate the history, and pressEnterto get out of the copy mode.
Personalization
Tmux is highly configurable by the file~/.tmux.conf. Some common customizations include:
- Change prefix toCtrl + a(similar to screen):
unbind C-b
set -g prefix C-a
bind C-a send-prefix - Activate the mouse to change panel and resize:
set -g mouse on - Define an information status bar:
set -g status-bg '#444444'
set -g status-fg '#ffffff'
set -g status-left '#[bg=#0066ff]#[fg=#ffffff] #S ' - Establish own shortcuts, for example,Ctrl + b +to create a vertical panel:
bind + split-window -h
After editing~/.tmux.conf, recharge the configuration withCtrl + b:followed bysource-file ~/.tmux.confor just reboot tmux.
Conclusion
The tmux command in Linux transforms the way we interact with the terminal, offering a layer of organization and persistence that is essential for administrators, developers and any user who needs to handle multiple tasks simultaneously. From simple panel creation to deep customization through configuration files, tmux adapts to various workflows and improves daily efficiency. If you have not yet tried it, spend a few minutes to install it and explore its shortcuts; you will soon discover why it is considered one of the most advanced and versatile terminal multiplexers available.


