Tmux?
tmux is a terminal multiplexer that enables you to create, access, and control multiple terminal sessions from a single screen. Key advantages include:
- Session Persistence: Detach from a session and re-attach later, preserving running processes even if your SSH connection drops.
- Window & Pane Management: Divide your terminal into multiple windows (tabs) and panes (splits).
- Scriptability: Automate terminal layouts and development environments.
Installation
Install tmux using your distribution’s native package manager:
Debian / Ubuntu / Linux Mint
Fedora / RHEL / CentOS
Arch Linux / Manjaro
| |
Basic Concepts & Usage Flow
A tmux hierarchy consists of three levels:
- Server / Session: A collection of windows managed by the background daemon.
- Window: A single screen within a session (like a browser tab).
- Pane: A subdivided section within a window (vertical or horizontal split).
| |
Command Line Workflow
| Action | Command |
|---|---|
| Start a new unnamed session | tmux |
| Start a named session | tmux new -s <session-name> |
| List active sessions | tmux ls |
| Attach to last session | tmux a or tmux attach |
| Attach to named session | tmux a -t <session-name> |
| Detach from current session | Press Ctrl+b then d |
| Kill a specific session | tmux kill-session -t <session-name> |
| Kill all tmux sessions | tmux kill-server |
Default Hotkeys Quick Reference
All tmux default shortcuts start with the Prefix key: Ctrl+b (written as Prefix).
Session Control
Prefixd: Detach from current session.Prefixs: Interactively select/switch session.Prefix$: Rename current session.Prefix(/): Switch to previous / next session.
Window Management
Prefixc: Create a new window.Prefix,: Rename current window.Prefixw: List and select windows/sessions interactively.Prefixn: Go to next window.Prefixp: Go to previous window.Prefix0..9: Switch to window by index number.Prefix&: Kill current window.
Pane Management
Prefix%: Split pane vertically (left | right).Prefix": Split pane horizontally (top / bottom).Prefixo: Swap/cycle focus to the next pane.PrefixArrow Keys: Move focus to adjacent pane (Up/Down/Left/Right).Prefixz: Toggle zoom on focused pane (full screen toggle).Prefixx: Kill current pane.Prefix{/}: Swap current pane with previous / next pane.PrefixSpace: Cycle through preset pane layouts.PrefixCtrl+Arrow: Resize current pane in 1-cell increments.
Copy / Scroll Mode
Prefix[: Enter Copy / Scroll mode.Use Arrow keys or Page Up/Down to navigate buffer.
Press
Spaceto start text selection.Press
Enterto copy selection to buffer and exit copy mode.Prefix]: Paste text from tmux copy buffer.Prefix#: View all buffer history.
Customization (~/.tmux.conf)
Create or edit ~/.tmux.conf to configure your tmux preferences.
| |