Skip to content

Tmux: Terminal Multiplexer for Power Users

DodaTech Updated 2026-06-22 5 min read

In this tutorial, you'll learn tmux for session management, split panes, window organization, custom key bindings, and configuration to handle multiple terminal tasks efficiently.

Why Tmux Matters

Developers regularly juggle multiple terminal tasks: running a dev server, editing files, checking logs, and executing database queries. Tmux lets you manage all these in a single window with keyboard-driven navigation. Sessions survive network disconnects, so your work persists after SSH drops.

By the end of this guide, you will confidently use tmux for daily development, manage sessions and Windows, and customize key bindings for speed.

What is Tmux?

Tmux is a terminal multiplexer. It allows you to run multiple terminal sessions inside one window. Think of it as a window manager for your terminal.

flowchart TD
  A[Terminal Window] --> B[Tmux Server]
  B --> C[Session 1]
  B --> D[Session 2]
  C --> E[Window 1: Editor]
  C --> F[Window 2: Server]
  C --> G[Window 3: Logs]
  E --> H[Pane 1: Code]
  E --> I[Pane 2: Terminal]

Installation

# macOS
brew install tmux

# Ubuntu/Debian
sudo apt install tmux -y

# Verify
tmux -V
# tmux 3.4

Starting Tmux

Launch tmux with a new session:

tmux new -s myproject

You see a green status bar at the bottom. This is your tmux session with session name, Windows, and pane info.

Core Concepts

Term Definition
Session A collection of Windows. Named sessions let you switch between contexts.
Window A full-screen view within a session. Like tabs in a browser.
Pane A split area within a window. Like split screens in an editor.
Prefix Key The key combination that precedes all tmux commands. Default is Ctrl-b.

Essential Key Bindings

Master these commands first:

Command Action
Ctrl-b c Create a new window
Ctrl-b p Switch to previous window
Ctrl-b n Switch to next window
Ctrl-b 0-9 Switch to window by number
Ctrl-b % Split pane vertically
Ctrl-b " Split pane horizontally
Ctrl-b arrow Move focus to adjacent pane
Ctrl-b d Detach from session
Ctrl-b [ Enter copy mode (scroll with arrows)

Example Workflow

# Start a new session
tmux new -s dev

# Inside tmux:
# Ctrl-b c creates a new window (now at window 1)
# Ctrl-b % splits vertically for side-by-side editing
# Run `top` in one pane, `tail -f server.log` in another
# Ctrl-b d detaches

# Reattach later
tmux attach -t dev

Session Management

# List all sessions
tmux ls

# Create named session
tmux new -s myproject

# Detach: Ctrl-b d

# Reattach to session
tmux attach -t myproject

# Kill session
tmux kill-session -t myproject

# Rename session (inside tmux)
tmux rename-session -t oldname newname

Expected Output for tmux ls

dev: 2 windows (created Mon Jun 22 09:15:00 2026)
myproject: 1 windows (created Mon Jun 22 09:30:00 2026)

Configuration File

Tmux reads ~/.tmux.conf on startup. Here is a starter config:

# ~/.tmux.conf

# Set prefix to Ctrl-a (easier reach)
set -g prefix C-a
unbind C-b
bind C-a send-prefix

# Enable mouse support
set -g mouse on

# Increase scrollback buffer
set -g history-limit 50000

# Status bar customization
set -g status-bg colour235
set -g status-fg white
set -g status-interval 60
set -g status-left '#[fg=green]#S '
set -g status-right '#[fg=yellow]%Y-%m-%d %H:%M'

# Reload config with Ctrl-a r
bind r source-file ~/.tmux.conf \; display-message "Config reloaded"

Reload the config:

tmux source-file ~/.tmux.conf

Copy Mode and Pasting

Copy mode lets you scroll and select text:

Ctrl-b [        # Enter copy mode
Use arrows      # Navigate
Space           # Start selection
Enter           # Copy selection
Ctrl-b ]        # Paste selection

Advanced Panes

# Resize pane (after prefix)
Ctrl-b Ctrl-arrow   # Resize pane in arrow direction

# Toggle pane zoom
Ctrl-b z            # Zoom pane fullscreen, press again to unzoom

# Close pane
Ctrl-b x            # Kill current pane (confirms first)

# Swap panes
Ctrl-b {            # Swap pane with previous
Ctrl-b }            # Swap pane with next

# Show pane numbers
Ctrl-b q            # Show numbers, press number to jump

Scripting Tmux

Create scripts for project environments:

#!/bin/bash
# ~/bin/dev-session.sh
SESSION="dev"

tmux new-session -d -s $SESSION

tmux rename-window -t $SESSION:0 "editor"
tmux send-keys -t $SESSION:0 "nvim ." C-m

tmux new-window -t $SESSION:1 -n "server"
tmux send-keys -t $SESSION:1 "npm run dev" C-m

tmux new-window -t $SESSION:2 -n "git"
tmux send-keys -t $SESSION:2 "git status" C-m

tmux select-window -t $SESSION:0

tmux attach -t $SESSION

Common Errors

Problem Cause Fix
"open terminal failed: missing or unsuitable terminal" TERM not set correctly Add set -g default-terminal "screen-256color" to config
Mouse scrolling scrolls history instead of terminal Mouse mode not enabled Add set -g mouse on to ~/.tmux.conf
Copy mode text selection not working Wrong key binding Use Ctrl-b [ then space to start selection
Session not found when reattaching Wrong session name Use tmux ls to verify session names
Status line missing information Config not reloaded Run tmux source-file ~/.tmux.conf

Practice Questions

1. What is the default prefix key in tmux?

Ctrl-b.

2. How do you split a window vertically in tmux?

Ctrl-b %.

3. What command lists all active tmux sessions?

tmux ls.

4. How do you detach from a tmux session without closing it?

Ctrl-b d.

5. What does set -g mouse on do in tmux configuration?

Enables mouse support for scrolling, selecting panes, and resizing.

Challenge

Write a Shell Script called tmux-dev.sh that launches a Python development environment with three Windows: one for Neovim editing, one for running the Flask dev server, and one for the Python REPL. Include split panes in the editor window.

Real-World Task

Configure your Docker development workflow using tmux. Start a tmux session named docker-dev with Windows for: running containers (docker ps -a), viewing logs (docker-compose logs -f), and executing commands inside containers (docker exec -it). Detach and reattach to verify session persistence.

Can tmux share a session with another user?

Yes. Use tmux -S /tmp/shared new -s shared and set the socket permissions. Both users attach with tmux -S /tmp/shared attach.

Does tmux support 256 colors?

Yes. Add set -g default-terminal "tmux-256color" to your .tmux.conf. Your terminal must also support 256 colors.

How is tmux different from GNU Screen?

Tmux offers better scripting, a cleaner configuration syntax, and more active development. Both serve the same purpose.

Built by the developers of Doda Browser, DodaZIP, and Durga Antivirus Pro.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro