Introduction
In the world of system administration and software development, working with multiple terminals simultaneously can significantly improve productivity. The tmux command in Linux presents a powerful solution for multiplexing terminal sessions, allowing you to split the screen into panes, create windows, and keep sessions active even after closing the SSH client. This article explores everything from basic concepts to advanced techniques to get the most out of tmux.
What is tmux?
Tmux (terminal multiplexer) is a program that allows you to access several terminals within a single window. It works as a server that manages sessions, each composed of one or more windows, and each window can be split into panes. This architecture facilitates work organization, as you can have a pane for editing code, another for viewing logs, and a third for executing commands, all without losing context.
Installation
In most Linux distributions, tmux is available in the official repositories. On Ubuntu or Debian, simply run:
sudo apt update && sudo apt install tmuxsudo dnf install tmuxon Fedorasudo pacman -S tmuxon Arch Linux
After installation, you can start tmux simply by typing tmux in the terminal. If you want it to start automatically when opening a new session, add the line if [ -z "$TMUX" ]; then tmux; fi at the end of your ~/.bashrc or ~/.zshrc file.
Basic Commands
The default tmux prefix is Ctrl+b. After pressing the prefix, you can type different commands:
- Ctrl+b c creates a new window.
- Ctrl+b , allows renaming the current window.
- Ctrl+b n and Ctrl+b p switch to the next or previous window.
- Ctrl+b % splits the current pane into two vertical panes.
- Ctrl+b " splits the current pane into two horizontal panes.
- Ctrl+b arrow (left, right, up, down) moves focus between panes.
- Ctrl+b z toggles zoom mode, expanding the active pane to full screen.
These shortcuts form the basis for navigating and organizing your work environment within tmux.
Managing Panes and Windows
In addition to keyboard shortcuts, tmux allows you to execute commands directly from the prefix command line. For example, Ctrl+b : opens the tmux prompt where you can type:
split-window -hto split vertically.split-window -vto split horizontally.resize-pane -L 5to reduce the width of the pane toward the left by 5 cells.select-layout even-horizontalto distribute panes evenly.
You can create named sessions with tmux new -s session_name, which is useful when working on multiple projects simultaneously. Each session maintains its own set of windows and panes, isolated from the rest.
S
This post is also available in ESPAÑOL.