tmux for Terminal Multiplexing and Productivity
Master tmux for managing multiple terminal sessions, persistent remote work, and an efficient command-line workflow.
What you'll learn
- ✓Core tmux concepts: sessions, windows, and panes
- ✓Essential keybindings for efficient terminal workflow
- ✓Configuring tmux and using it for persistent remote sessions
Prerequisites
- •Basic Linux command line
- •Familiarity with SSH for remote work
Why tmux?
tmux (terminal multiplexer) lets you run multiple terminal sessions inside a single window, split your screen into panes, and — most importantly — keep your sessions alive even when you disconnect. If your SSH connection drops, tmux preserves everything exactly as you left it.
tmux solves three problems:
- Persistence — Sessions survive disconnections and can be reattached from anywhere.
- Multiplexing — Multiple terminal windows and panes in a single connection.
- Organization — Group related work into named sessions and windows.
Installing tmux
# Debian/Ubuntu
sudo apt install tmux
# Fedora/RHEL
sudo dnf install tmux
# macOS
brew install tmux
# Verify installation
tmux -V
Core Concepts
tmux has three layers of organization:
- Session — A collection of windows. Think of it as a workspace or project.
- Window — A full-screen terminal tab within a session.
- Pane — A split within a window, showing a separate terminal.
All tmux commands start with a prefix key, which is Ctrl+b by default. You press the prefix, release it, then press the command key.
Session Management
# Start a new named session
tmux new -s project
# Detach from the current session (prefix + d)
# Press Ctrl+b, then d
# List all sessions
tmux ls
# Reattach to a session
tmux attach -t project
# Reattach or create if it doesn't exist
tmux new -A -s project
# Kill a session
tmux kill-session -t project
# Switch between sessions (prefix + s)
# Press Ctrl+b, then s -- shows an interactive session picker
The killer feature: start a session on a remote server, detach, close your laptop, go home, SSH back in, and tmux attach to pick up exactly where you left off.
Window Management
Windows are like tabs inside a session:
| Keybinding | Action |
|---|---|
Ctrl+b c | Create a new window |
Ctrl+b , | Rename the current window |
Ctrl+b n | Next window |
Ctrl+b p | Previous window |
Ctrl+b 0-9 | Jump to window by number |
Ctrl+b w | Interactive window picker |
Ctrl+b & | Close the current window |
# A typical workflow: one session, multiple windows
tmux new -s myproject
# Window 0: editor (vim/nvim)
# Ctrl+b c -> Window 1: server (npm run dev)
# Ctrl+b c -> Window 2: git operations
# Ctrl+b c -> Window 3: logs (tail -f)
Pane Management
Panes split a window into multiple terminals:
| Keybinding | Action |
|---|---|
Ctrl+b % | Split vertically (left/right) |
Ctrl+b " | Split horizontally (top/bottom) |
Ctrl+b arrow | Move between panes |
Ctrl+b z | Toggle zoom (fullscreen) on current pane |
Ctrl+b x | Close the current pane |
Ctrl+b { | Swap pane left |
Ctrl+b } | Swap pane right |
Ctrl+b Space | Cycle through pane layouts |
Ctrl+b q | Show pane numbers (press number to jump) |
Resizing panes:
# Hold Ctrl+b, then press arrow keys repeatedly
# Or use the resize command:
# Ctrl+b :resize-pane -D 10 (down 10 rows)
# Ctrl+b :resize-pane -U 10 (up 10 rows)
# Ctrl+b :resize-pane -L 10 (left 10 columns)
# Ctrl+b :resize-pane -R 10 (right 10 columns)
Copy Mode (Scrollback)
By default, you cannot scroll with your mouse in tmux. Instead, use copy mode:
# Enter copy mode
# Ctrl+b [
# Navigate with arrow keys, Page Up/Down, or vim keys (hjkl)
# Press q or Escape to exit copy mode
# Search backward
# Ctrl+b [ then press / and type your search term (with vi keys)
# Or press Ctrl+s for forward search in emacs mode
# Copy text (vi mode):
# Move to start, press Space, move to end, press Enter
# Paste: Ctrl+b ]
Configuring tmux
Create ~/.tmux.conf to customize tmux:
# Change prefix from Ctrl+b to Ctrl+a (easier to reach)
unbind C-b
set -g prefix C-a
bind C-a send-prefix
# Start window numbering at 1 (instead of 0)
set -g base-index 1
setw -g pane-base-index 1
# Renumber windows when one is closed
set -g renumber-windows on
# Enable mouse support (scrolling, clicking panes, resizing)
set -g mouse on
# Increase scrollback buffer
set -g history-limit 50000
# Reduce escape key delay (important for vim users)
set -sg escape-time 10
# Use vi keys in copy mode
setw -g mode-keys vi
# Easier pane splitting (| and -)
bind | split-window -h -c "#{pane_current_path}"
bind - split-window -v -c "#{pane_current_path}"
# Open new windows in the current directory
bind c new-window -c "#{pane_current_path}"
# Reload config file
bind r source-file ~/.tmux.conf \; display "Config reloaded!"
# Better pane navigation (vim-style)
bind h select-pane -L
bind j select-pane -D
bind k select-pane -U
bind l select-pane -R
# Resize panes with vim-style keys
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-style 'bg=#333333 fg=#ffffff'
set -g status-left '#[fg=#88cc88]#S '
set -g status-right '%H:%M %d-%b-%Y'
set -g status-left-length 30
After editing, reload the config:
# From inside tmux
tmux source-file ~/.tmux.conf
# Or use the keybinding we defined above: prefix + r
Practical Workflows
Remote Server Administration
# SSH into a server and start a persistent session
ssh server
tmux new -s admin
# Window 0: monitoring
htop
# Ctrl+b c -> Window 1: logs
journalctl -f
# Ctrl+b c -> Window 2: shell for commands
# Detach: Ctrl+b d
# Disconnect SSH. Come back later:
ssh server
tmux attach -t admin
# Everything is still running!
Development Environment
# Create a dev session with a scripted layout
tmux new -s dev -d
tmux send-keys -t dev 'nvim .' Enter
tmux split-window -t dev -h -p 30
tmux send-keys -t dev 'npm run dev' Enter
tmux split-window -t dev -v -p 40
tmux send-keys -t dev 'git status' Enter
tmux select-pane -t dev:.0
tmux attach -t dev
Save this as a shell script for your project to get a consistent layout every time.
Pair Programming
tmux sessions can be shared between multiple users:
# User 1 creates a session
tmux new -s pairing
# User 2 attaches to the same session (both see the same thing)
tmux attach -t pairing
# For independent cursors, User 2 can use:
tmux new -t pairing -s user2
Useful Commands Reference
# Send a command to a tmux pane from outside tmux
tmux send-keys -t session:window.pane 'make build' Enter
# Capture pane contents to a file
tmux capture-pane -p -t session:0.0 > /tmp/pane-output.txt
# List all keybindings
tmux list-keys
# Show current options
tmux show-options -g
# Kill the tmux server (all sessions)
tmux kill-server
tmux Plugin Manager (TPM)
For additional features, install TPM:
git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm
Add to your ~/.tmux.conf:
# List of plugins
set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'tmux-plugins/tmux-sensible'
set -g @plugin 'tmux-plugins/tmux-resurrect' # save/restore sessions
set -g @plugin 'tmux-plugins/tmux-continuum' # auto-save sessions
# Initialize TPM (keep at the bottom of tmux.conf)
run '~/.tmux/plugins/tpm/tpm'
Press prefix + I to install plugins.
Summary
tmux is an essential tool for anyone who works in the terminal, especially on remote servers. The core workflow is: create named sessions for different projects, use windows as tabs, split windows into panes for side-by-side work, and detach/reattach to keep everything alive across disconnections. Customize ~/.tmux.conf to match your workflow, and you will find that tmux becomes the foundation of your terminal productivity.
Related articles
- Linux Linux tmux and screen Tutorial: Persistent Terminal Sessions
A practical guide to tmux and GNU screen for persistent shells, splits, and remote workflows, with side-by-side commands and tips for daily use.
- Linux The Linux Terminal: A Beginner's Guide
Open a terminal, read the prompt, and learn the handful of conventions that make every command-line tool consistent. The foundation for everything else you will do on Linux.
- Linux Linux awk and sed: Text Processing Power Tools
Master awk and sed for text processing on Linux. Learn pattern matching, field extraction, in-place editing, and real-world one-liners for log analysis.
- Linux Linux systemd: Create and Manage Custom Services
Learn how to create, configure, and manage custom systemd service units on Linux. Covers unit files, dependencies, timers, and troubleshooting.