
Master Tmux in 2025: The Ultimate Tmux Cheat Sheet
This cheat sheet summarizes the most essential tmux commands for version 3.5a (released October 2024), organized by category, with real-world examples to illustrate their use. Tmux is a terminal multiplexer that allows you to manage multiple terminal sessions, windows, and panes within a single terminal, making it invaluable for developers, system administrators, and anyone working in a terminal-heavy environment. The default prefix key is Ctrl-b, and commands are executed by pressing the prefix followed by the command key (e.g., Ctrl-b c means press Ctrl-b, release, then press c). This guide assumes the default key bindings and vi mode for copy operations, but tmux is highly customizable via ~/.tmux.conf.
Session Management
Sessions are the top-level containers in tmux, allowing you to group windows and persist them across terminal connections. They are particularly useful for maintaining workflows over SSH or after disconnecting.
Command | Description | Example |
---|---|---|
tmux or tmux new-session | Starts a new tmux session | tmux new-session begins a new session with a single window. |
tmux new-session -s <name> | Starts a new session with a specified name | tmux new-session -s dev creates a session named “dev” for development work. |
tmux list-sessions | Lists all active tmux sessions | tmux list-sessions might output dev: 1 windows (created Mon Apr 19 09:00:00 2025). |
tmux attach-session -t <name> | Attaches to an existing session by name | tmux attach-session -t dev reconnects to the “dev” session. |
Ctrl-b d | Detaches the current session, keeping it running | Press Ctrl-b d to detach and return to the shell, leaving the session active. |
Ctrl-b $ | Prompts to rename the current session | Press Ctrl-b $, enter “projectX”, to rename the session to “projectX”. |
Real-World Example: Imagine you’re working on a remote server via SSH. You run tmux new-session -s coding to start a session, open an editor, and start a build process. If your SSH connection drops, you can reconnect later and run tmux attach-session -t coding to resume exactly where you left off. To detach intentionally, press Ctrl-b d before closing the terminal.
Window Management
Windows are like tabs within a tmux session, each containing one or more panes. They allow you to organize tasks, such as running different applications or monitoring processes.
Command | Description | Example |
---|---|---|
Ctrl-b c | Creates a new window | Press Ctrl-b c to open a new window with a fresh shell. |
Ctrl-b n | Switches to the next window | Press Ctrl-b n to move to the next window in the session. |
Ctrl-b p | Switches to the previous window | Press Ctrl-b p to return to the previous window. |
Ctrl-b <number> | Switches to the window with the specified number (0–9) | Press Ctrl-b 2 to jump to window number 2. |
Ctrl-b l | Switches to the last active window | Press Ctrl-b l to toggle between the current and previous window. |
Ctrl-b , | Prompts to rename the current window | Press Ctrl-b ,, enter “editor”, to name the window “editor”. |
Ctrl-b & | Closes the current window after confirmation | Press Ctrl-b & and confirm to close the window. |
Real-World Example: While working in a session, you press Ctrl-b c to create a window for editing code in vim. You name it “code” with Ctrl-b ,. You create another window (Ctrl-b c) for running tests, naming it “tests”. You switch between them using Ctrl-b n or Ctrl-b 1 to jump directly to the “code” window.
Pane Management
Panes divide a window into multiple terminal instances, allowing you to view and interact with several processes simultaneously within the same window.
Command | Description | Example |
---|---|---|
Ctrl-b % | Splits the current pane vertically (side by side) | Press Ctrl-b % to split the window into two vertical panes. |
Ctrl-b “ | Splits the current pane horizontally (stacked) | Press Ctrl-b ” to split the window into two horizontal panes. |
Ctrl-b <arrow key> | Switches to the adjacent pane in the specified direction | Press Ctrl-b Right to move to the pane on the right. |
Ctrl-b q | Displays pane numbers briefly; press a number to switch | Press Ctrl-b q, then 1 to switch to pane 1. |
Ctrl-b { or Ctrl-b } | Swaps the current pane with the previous or next pane | Press Ctrl-b } to swap the current pane with the one below it. |
Ctrl-b Ctrl-<arrow key> | Resizes the current pane in the specified direction | Press Ctrl-b Ctrl-Up to increase the pane’s height. |
Ctrl-b z | Toggles zoom (full-screen) for the current pane | Press Ctrl-b z to zoom the pane, press again to unzoom. |
Ctrl-b x | Closes the current pane after confirmation | Press Ctrl-b x and confirm to close the pane. |
Real-World Example: In a window, you press Ctrl-b % to create a vertical split, running htop in the left pane to monitor system resources and tail -f log.txt in the right pane to watch logs. You press Ctrl-b Right to switch to the log pane and Ctrl-b Ctrl-Left to make it wider. To focus on logs, press Ctrl-b z to zoom, then Ctrl-b z to return to the split view.
Copy Mode
Copy mode allows you to scroll through terminal output, select text, and copy it to a buffer for pasting. This guide assumes vi mode, which is common but can be changed to emacs in ~/.tmux.conf.
Command | Description | Example |
---|---|---|
Ctrl-b [ | Enters copy mode to scroll and select text | Press Ctrl-b [ to enter copy mode and scroll through output. |
Arrow keys, Space, Enter (vi mode) | Navigate with arrow keys; start selection with Space, copy with Enter | In copy mode, move to text, press Space, select with arrows, press Enter. |
Ctrl-b ] | Pastes the most recently copied buffer | Press Ctrl-b ] to paste the copied text into the current pane. |
Ctrl-b = | Lists buffers and allows pasting a specific one | Press Ctrl-b =, select a buffer, and press Enter to paste. |
Real-World Example: You’re debugging a server and see an error in the terminal. Press Ctrl-b [ to enter copy mode, use arrow keys to move to the error, press Space to start selecting, move to highlight the text, and press Enter to copy. Switch to another pane with Ctrl-b Left and press Ctrl-b ] to paste the error into a file or command.
Miscellaneous
These commands provide additional functionality, such as accessing help, checking the time, or enabling mouse support.
Command | Description | Example |
---|---|---|
Ctrl-b ? | Lists all key bindings | Press Ctrl-b ? to view all available key bindings. |
Ctrl-b t | Displays the current time | Press Ctrl-b t to show the time in the current pane. |
Ctrl-b ~ | Shows previous tmux messages | Press Ctrl-b ~ to view error or status messages. |
Ctrl-b f | Searches for a window by name or content | Press Ctrl-b f, enter “code”, to find the “code” window. |
set -g mouse on | Enables mouse support (add to ~/.tmux.conf) | Add set -g mouse on to ~/.tmux.conf to click panes or resize with the mouse. |
Real-World Example: You’re unsure about a key binding, so you press Ctrl-b ? to browse the list. To check the server time, press Ctrl-b t. If you prefer mouse interaction, you add set -g mouse on to ~/.tmux.conf, allowing you to click to switch panes or drag to resize them.
Real-World Scenarios
- Setting Up a Development Environment:
- Run tmux new-session -s dev to start a session.
- Press Ctrl-b c to create a window for vim, name it “code” with Ctrl-b ,.
- Press Ctrl-b % to split the window, running python manage.py runserver in the new pane.
- Press Ctrl-b d to detach and reconnect later with tmux attach-session -t dev.
- Monitoring and Debugging:
- Start a session with tmux new-session -s monitor.
- Press Ctrl-b ” to split horizontally, running htop in the top pane and tail -f /var/log/syslog in the bottom.
- Press Ctrl-b q to see pane numbers and 1 to switch to the log pane.
- Copy an error with Ctrl-b [, select with Space and Enter, then paste into a file with Ctrl-b ].
- Collaborative Work:
- Create a session with tmux new-session -s team.
- Share the session name and server details with a colleague, who attaches using tmux attach-session -t team.
- Press Ctrl-b c to open a window for a shared editor, and Ctrl-b f to find it later by name.
Notes
- Customization: Tmux’s flexibility allows you to change the prefix (e.g., to Ctrl-a) or key bindings in ~/.tmux.conf. For example, to change the prefix, add set -g prefix C-a and unbind C-b.
- Vi vs. Emacs: Copy mode defaults to emacs unless set -g mode-keys vi is in ~/.tmux.conf. This guide uses vi mode for copy commands.
- Version Information: This cheat sheet is based on tmux 3.5a, the latest release as of October 2024. Check the tmux GitHub for updates.
- Mouse Support: Enabling mouse support requires editing ~/.tmux.conf and reloading with tmux source-file ~/.tmux.conf.
For advanced features, such as scripting tmux or integrating with tools like iTerm2, consult the tmux Wiki or tmux Man Page. If you encounter issues, the tmux mailing list is a valuable resource.
Key Citations
- tmux Wiki Getting Started Page
- tmux OpenBSD Manual Page
- tmux GitHub Repository
- tmux Mailing List for Discussion