tmux Cheat Sheet
A comprehensive guide to tmux, a terminal multiplexer that allows you to manage multiple terminal sessions within a single window. Ideal for managing long-running processes, organizing workspaces, and enhancing productivity.
Table of Contents
- Installation
- Starting tmux
- Basic Commands
- Session Management
- Window Management
- Pane Management
- Customization
- Useful Tips & Tricks
- Common Use Cases
Installation
Ensure tmux is installed on your Ubuntu WSL environment.
sudo apt update
sudo apt install tmuxVerify installation:
tmux -V
# Example Output: tmux 3.2aStarting tmux
Start a New Session
tmuxStart a New Session with a Name
tmux new -s mysessionAttach to an Existing Session
tmux attach -t mysession
# or
tmux a -t mysessionList All Sessions
tmux lsDetach from Current Session
- Keyboard Shortcut:
Ctrl + bthend
Basic Commands
tmux uses a prefix key (Ctrl + b by default) followed by a command key.
- Prefix Key:
Ctrl + b
Common Prefix Commands
| Action | Command |
|---|---|
| Send prefix key to application | Ctrl + b then Ctrl + b |
| List key bindings | Ctrl + b then ? |
| Reload configuration | Ctrl + b then : then type source-file ~/.tmux.conf |
Session Management
Create a New Session
tmux new -s mysessionList Sessions
tmux lsAttach to a Session
tmux attach -t mysessionDetach from Session
- Keyboard Shortcut:
Ctrl + bthend
Kill a Session
tmux kill-session -t mysessionRename a Session
- Command:
tmux rename-session -t oldname newname
Window Management
Each session can have multiple windows, akin to tabs.
Create a New Window
- Keyboard Shortcut:
Ctrl + bthenc
Switch to Next Window
- Keyboard Shortcut:
Ctrl + bthenn
Switch to Previous Window
- Keyboard Shortcut:
Ctrl + bthenp
Select Window by Number
Keyboard Shortcut:
Ctrl + bthen<window-number>Example:
Ctrl + bthen2to switch to window 2.
Rename Current Window
- Keyboard Shortcut:
Ctrl + bthen,
Close Current Window
- Keyboard Shortcut:
Ctrl + bthen&
Pane Management
Split windows into multiple panes for parallel tasks.
Split Horizontally
- Keyboard Shortcut:
Ctrl + bthen"
Split Vertically
- Keyboard Shortcut:
Ctrl + bthen%
Resize Panes
Keyboard Shortcut:
Ctrl + bthen:and typeresize-pane -D/-U/-L/-RAlternatively, use
Ctrl + bthenCtrl + arrow keys(if configured).
Close Current Pane
- Keyboard Shortcut:
Ctrl + bthenx
Swap Panes
- Keyboard Shortcut:
Ctrl + btheno
Customization
Customize tmux behavior via the ~/.tmux.conf file.
Common Configurations
# Set prefix to Ctrl + a (optional)
# set-option -g prefix C-a
# unbind default prefix
# unbind C-b
# bind new prefix
# bind C-a send-prefix
# Enable mouse support
set -g mouse on
# Set window splitting shortcuts
bind | split-window -h
bind - split-window -v
# Reload config with prefix + r
bind r source-file ~/.tmux.conf \; display-message "Config Reloaded!"
# Enable vim-style pane switching
bind h select-pane -L
bind j select-pane -D
bind k select-pane -U
bind l select-pane -R
# Set status bar
set -g status-bg colour235
set -g status-fg colour136
set -g status-left '[: #S | #I:#W]'Applying Configuration
After editing ~/.tmux.conf, reload it:
tmux source-file ~/.tmux.confUseful Tips & Tricks
- Copy Mode: Enter copy mode to navigate and copy text.
- Keyboard Shortcut:
Ctrl + bthen[ - Exit Copy Mode:
qorEsc
- Keyboard Shortcut:
- Search in Copy Mode:
- Press
/and type the search query.
- Press
- Scroll Up/Down:
- Use arrow keys or
PgUp/PgDnin copy mode.
- Use arrow keys or
- Synchronize Panes:
- Execute the same command in all panes.
- Command:
Ctrl + bthen:setw synchronize-panes on
- Lock tmux Session:
- Command:
Ctrl + bthen:lock-server
- Command:
- Display Current Key Bindings:
- Keyboard Shortcut:
Ctrl + bthen?
- Keyboard Shortcut:
Common Use Cases
Running Multiple Processes
Organize different processes in separate panes or windows.
# Window 1: Development server
tmux new -s dev
# Inside tmux
# Pane 1: Run server
python manage.py runserver
# Pane 2: Monitor logs
tail -f logs/server.logRemote Workflows
Maintain persistent sessions across SSH connections.
# On remote server
tmux new -s remote
# Start long-running task
python train_model.py
# Detach and disconnect
Ctrl + b then d
# Reattach later
tmux attach -t remoteManaging Git Operations
Use separate panes for editing, committing, and viewing status.
# Split window vertically
Ctrl + b then %
# Pane 1: Edit code
vim main.py
# Pane 2: Git status and commits
git status
git commit -m "Update main.py"Monitoring System Resources
Run monitoring tools alongside development.
# Split window horizontally
Ctrl + b then "
# Pane 1: Develop
vim script.py
# Pane 2: Monitor
htopExample Workflow
Start a New Session:
tmux new -s ai_projectCreate Windows:
- Window 1: Code Editor
- Keyboard Shortcut:
Ctrl + bthenc - Commands:
bash vim main.py
- Keyboard Shortcut:
- Window 2: Terminal
- Keyboard Shortcut:
Ctrl + bthenc - Commands:
bash python main.py
- Keyboard Shortcut:
- Window 3: Logs
- Keyboard Shortcut:
Ctrl + bthenc - Commands:
bash tail -f logs/output.log
- Keyboard Shortcut:
- Window 1: Code Editor
Navigate Between Windows:
- Next Window:
Ctrl + bthenn - Previous Window:
Ctrl + bthenp - Select Window by Number:
Ctrl + bthen1,2,3, etc.
- Next Window:
Detach and Reattach:
- Detach:
Ctrl + bthend - Reattach:
tmux attach -t ai_project
- Detach: