tmux Command
Advanced terminal multiplexer for creating and managing multiple terminal sessions, windows, and panes with powerful features and customization.
Syntax
tmux [command] [options]
tmux new-session [-s session-name]
tmux attach-session [-t session-name]
tmux is a terminal multiplexer that enables multiple terminal sessions to be accessed simultaneously in a single window, with advanced features like pane splitting and session persistence.
Common Commands
| Command |
Description |
tmux |
Start new tmux session |
tmux new-session -s name |
Create named session |
tmux attach -t name |
Attach to session |
tmux list-sessions |
List all sessions |
tmux kill-session -t name |
Kill specific session |
tmux detach |
Detach from current session |
tmux split-window |
Split window into panes |
tmux new-window |
Create new window |
Basic Usage
Session management
# Start new session
tmux
tmux new-session
# Start named session
tmux new-session -s mysession
tmux new -s work
# List sessions
tmux list-sessions
tmux ls
# Attach to session
tmux attach-session -t mysession
tmux attach -t work
tmux a -t work
# Detach from session (inside tmux)
# Ctrl+B, D
Create, manage, and navigate tmux sessions
Session operations
# Kill session
tmux kill-session -t mysession
# Kill all sessions
tmux kill-server
# Rename session
tmux rename-session -t old-name new-name
# Create session with command
tmux new-session -s build -d 'make -j4'
# Create session in specific directory
tmux new-session -s project -c /path/to/project
Advanced session operations and management
Key Bindings (Prefix: Ctrl+B)
Session and window management
| Key Combination |
Action |
Ctrl+B, D |
Detach from session |
Ctrl+B, C |
Create new window |
Ctrl+B, N |
Next window |
Ctrl+B, P |
Previous window |
Ctrl+B, 0-9 |
Switch to window number |
Ctrl+B, L |
Last window |
Ctrl+B, W |
List windows |
Ctrl+B, , |
Rename window |
Ctrl+B, & |
Kill window |
Pane management
| Key Combination |
Action |
Ctrl+B, % |
Split pane vertically |
Ctrl+B, " |
Split pane horizontally |
Ctrl+B, Arrow |
Switch between panes |
Ctrl+B, O |
Next pane |
Ctrl+B, ; |
Last pane |
Ctrl+B, X |
Kill pane |
Ctrl+B, Z |
Zoom pane (toggle) |
Ctrl+B, Space |
Cycle pane layouts |
Ctrl+B, { |
Move pane left |
Ctrl+B, } |
Move pane right |
Other useful bindings
| Key Combination |
Action |
Ctrl+B, ? |
Show help (list key bindings) |
Ctrl+B, : |
Command prompt |
Ctrl+B, [ |
Copy mode (scroll/search) |
Ctrl+B, ] |
Paste buffer |
Ctrl+B, S |
List sessions |
Ctrl+B, $ |
Rename session |
Ctrl+B, T |
Show time |
Window and Pane Management
Working with windows
# Create new window
# Ctrl+B, C
# Create window with name
tmux new-window -n editor
# Create window with command
tmux new-window -n logs 'tail -f /var/log/syslog'
# Switch between windows
# Ctrl+B, 0-9 (window number)
# Ctrl+B, N (next)
# Ctrl+B, P (previous)
# Ctrl+B, L (last)
# Rename window
# Ctrl+B, , (then type new name)
tmux rename-window newname
# List windows
# Ctrl+B, W
tmux list-windows
Create and manage multiple windows within sessions
Working with panes
# Split panes
# Ctrl+B, % (vertical split)
# Ctrl+B, " (horizontal split)
# Navigate panes
# Ctrl+B, Arrow keys
# Ctrl+B, O (next pane)
# Ctrl+B, ; (last pane)
# Resize panes
# Ctrl+B, Ctrl+Arrow keys
tmux resize-pane -L 10 # Left
tmux resize-pane -R 10 # Right
tmux resize-pane -U 5 # Up
tmux resize-pane -D 5 # Down
# Zoom pane
# Ctrl+B, Z (toggle zoom)
# Close pane
# Ctrl+B, X (confirm with y)
exit # or just exit the shell
Split windows into panes and manage layouts
Pane layouts
# Cycle through layouts
# Ctrl+B, Space
# Specific layouts
tmux select-layout even-horizontal
tmux select-layout even-vertical
tmux select-layout main-horizontal
tmux select-layout main-vertical
tmux select-layout tiled
# Custom layout
tmux select-layout "main-vertical,162x48,0,0{81x48,0,0,0,80x48,82,0,1}"
# Move panes
# Ctrl+B, { (move left)
# Ctrl+B, } (move right)
tmux swap-pane -U # Up
tmux swap-pane -D # Down
Organize panes with different layouts
Copy Mode and Scrolling
Copy mode navigation
# Enter copy mode
# Ctrl+B, [
# Navigation in copy mode (vi-style)
# h, j, k, l - move cursor
# w, b - word forward/backward
# 0, $ - beginning/end of line
# g, G - top/bottom of buffer
# Ctrl+F, Ctrl+B - page down/up
# / - search forward
# ? - search backward
# n, N - next/previous search result
# Exit copy mode
# q or Escape
Navigate and search through terminal history
Copy and paste
# Copy mode selection (vi-style)
# Space - start selection
# Enter - copy selection
# v - start selection (visual mode)
# y - copy selection
# Paste
# Ctrl+B, ]
# List paste buffers
tmux list-buffers
# Show buffer content
tmux show-buffer
# Save buffer to file
tmux save-buffer ~/tmux-buffer.txt
# Load buffer from file
tmux load-buffer ~/tmux-buffer.txt
Copy text and manage paste buffers
Configuration
Basic configuration (~/.tmux.conf)
# ~/.tmux.conf example configuration
# Change prefix key from Ctrl+B to Ctrl+A
unbind C-b
set-option -g prefix C-a
bind-key C-a send-prefix
# Enable mouse support
set -g mouse on
# Start windows and panes at 1, not 0
set -g base-index 1
setw -g pane-base-index 1
# Reload config file
bind r source-file ~/.tmux.conf \; display-message "Config reloaded!"
# Split panes using | and -
bind | split-window -h
bind - split-window -v
unbind '"'
unbind %
# Switch panes using Alt+arrow without prefix
bind -n M-Left select-pane -L
bind -n M-Right select-pane -R
bind -n M-Up select-pane -U
bind -n M-Down select-pane -D
Basic tmux configuration options
Advanced configuration
# ~/.tmux.conf advanced settings
# Set default terminal mode to 256color
set -g default-terminal "screen-256color"
# Enable vi mode
setw -g mode-keys vi
# Copy mode bindings
bind-key -T copy-mode-vi v send-keys -X begin-selection
bind-key -T copy-mode-vi y send-keys -X copy-selection
bind-key -T copy-mode-vi r send-keys -X rectangle-toggle
# Pane resizing
bind -r H resize-pane -L 5
bind -r J resize-pane -D 5
bind -r K resize-pane -U 5
bind -r L resize-pane -R 5
# Status bar customization
set -g status-bg black
set -g status-fg white
set -g status-left '#[fg=green]#S '
set -g status-right '#[fg=yellow]#(uptime | cut -d "," -f 1) #[fg=cyan]%Y-%m-%d %H:%M'
# Window status
setw -g window-status-current-style 'fg=black bg=white bold'
# Pane borders
set -g pane-border-style 'fg=colour238'
set -g pane-active-border-style 'fg=colour51'
Advanced tmux configuration and customization
Applying configuration
# Reload configuration
tmux source-file ~/.tmux.conf
# Or inside tmux session
# Ctrl+B, : (command mode)
# source-file ~/.tmux.conf
# Check current configuration
tmux show-options -g
tmux show-window-options -g
# List key bindings
tmux list-keys
# Show specific option
tmux show-options -g prefix
Apply and manage tmux configuration
Practical Examples
Development workflow
# Create development session
tmux new-session -s dev -c ~/project
# Window 0: Editor
# Ctrl+B, , (rename to "editor")
vim src/main.py
# Window 1: Server
# Ctrl+B, C (new window)
# Ctrl+B, , (rename to "server")
python manage.py runserver
# Window 2: Database
# Ctrl+B, C (new window)
# Ctrl+B, , (rename to "database")
mysql -u user -p database
# Window 3: Logs (split panes)
# Ctrl+B, C (new window)
# Ctrl+B, , (rename to "logs")
tail -f /var/log/app.log
# Ctrl+B, " (horizontal split)
tail -f /var/log/error.log
Set up a complete development environment
System monitoring
# Create monitoring session
tmux new-session -s monitor
# Split into 4 panes
# Ctrl+B, " (horizontal split)
# Ctrl+B, % (vertical split on top)
# Ctrl+B, Down Arrow, % (vertical split on bottom)
# Pane 1: System