Articles

tmux Tutorial: Sessions, Windows, and Panes for Beginners

tmux is a terminal multiplexer that keeps shells running after you disconnect and splits one terminal into panes. A hands-on beginner's tutorial.

The Lycoris Team The Lycoris Team · · 5 min read
A dark code editor with syntax-highlighted text

tmux is a terminal multiplexer: a program that runs many shell sessions inside a single terminal window, lets you split that window into panes, and — most importantly — keeps everything running after you disconnect. Close your laptop, lose your SSH connection, or switch machines, and your processes and layout are still there when you reattach. Once that clicks, it’s hard to go back.

This tutorial covers the mental model, the essential keybindings, and a small starter config. The project’s official documentation lives on the tmux wiki.

Install tmux

tmux is available from every major package manager:

# Debian / Ubuntu
sudo apt install tmux

# macOS with Homebrew
brew install tmux

# Fedora
sudo dnf install tmux

Check it worked with tmux -V.

The mental model: server, sessions, windows, panes

tmux has four layers, and naming them correctly makes everything else easier.

  • Server. A background process that starts automatically the first time you run tmux. It owns everything below and keeps running when you disconnect.
  • Session. A named workspace, typically one per project. You attach to and detach from sessions.
  • Window. A full-screen tab inside a session. A session can have many windows, listed in the status bar at the bottom.
  • Pane. A split within a window. Each pane runs its own shell.

Your terminal is just a client viewing one session. That separation is why detaching doesn’t kill anything: the client goes away, the server and its sessions don’t.

The prefix key

Almost every tmux command starts with a prefix, which is Ctrl-b by default. You press and release the prefix, then press the command key. In this guide, prefix d means “press Ctrl-b, release, then press d.” If you’ve used Vim or Emacs, the idea of a modal leader key will feel familiar.

Step 1: Create and leave a session

Start a named session:

tmux new -s blog

You’re now inside tmux, with a green status bar along the bottom. Run something long-lived — a dev server, a log tail, a build watcher.

Now detach with prefix d. You’re back in your plain shell, but the session is still running. List sessions and reattach:

tmux ls
tmux attach -t blog

Everything is exactly as you left it. This is the killer feature for remote work: start tmux right after connecting over SSH (ideally with key-based authentication), and a dropped connection no longer kills your migration or your long-running job.

Step 2: Work with windows

Windows are tmux’s tabs.

KeysAction
prefix cCreate a new window
prefix n / prefix pNext / previous window
prefix 0–9Jump to a window by number
prefix ,Rename the current window
prefix wPick a window from an interactive list
prefix &Kill the current window (asks to confirm)

A common layout is one window for your editor, one for a server, and one for Git and ad-hoc commands.

Step 3: Split into panes

Panes let you see several shells at once.

KeysAction
prefix %Split left and right
prefix "Split top and bottom
prefix + arrow keyMove to the pane in that direction
prefix oCycle through panes
prefix zZoom the current pane to full window and back
prefix xKill the current pane (asks to confirm)
prefix SpaceCycle through preset layouts

Zoom is underrated: keep a split layout for monitoring, then press prefix z to temporarily focus on one pane without losing the arrangement.

Step 4: Scroll and copy

Your terminal’s scrollback doesn’t see tmux’s history, so scrolling works differently. Press prefix [ to enter copy mode. Now you can scroll with the arrow keys or Page Up and Page Down, and search with / or ? depending on your key mode. Press q to leave.

Copying text in copy mode depends on whether tmux is in emacs or vi key mode, which defaults based on your EDITOR environment variable. The simplest option for beginners is to enable the mouse (below) and select with it.

Step 5: Manage sessions

As you collect sessions for different projects, a few more commands help:

Keys / commandAction
prefix sInteractive session switcher
prefix $Rename the current session
tmux kill-session -t blogDestroy a session from the shell
prefix ?List every keybinding

Pairing sessions with project directories works nicely alongside Git worktrees: one session per worktree keeps parallel branches and their running processes cleanly separated.

Step 6: A starter config

tmux reads ~/.tmux.conf when the server starts. A minimal, widely used starting point:

# Enable mouse: click panes, resize splits, scroll
set -g mouse on

# Number windows and panes from 1, matching the keyboard
set -g base-index 1
setw -g pane-base-index 1

# Larger scrollback
set -g history-limit 50000

# More memorable split keys that open in the current directory
bind | split-window -h -c "#{pane_current_path}"
bind - split-window -v -c "#{pane_current_path}"

# Reload this file with prefix r
bind r source-file ~/.tmux.conf \; display "Config reloaded"

Many people also remap the prefix to Ctrl-a, which is easier to reach:

unbind C-b
set -g prefix C-a
bind C-a send-prefix

After editing the file, reload it in a running server with tmux source-file ~/.tmux.conf, or prefix r once the binding above is in place.

Habits that make tmux stick

  • Always name sessions. tmux new -s api beats remembering that session 3 was the API.
  • Reattach, don’t recreate. tmux new -A -s api attaches if the session exists and creates it if not — handy in shell aliases or a Makefile target.
  • Combine with fuzzy finders. A small script using fzf to pick a project directory and open or attach to a matching session turns project switching into two keystrokes.
  • Learn five keys first. prefix c, prefix %, prefix ", prefix z, and prefix d cover most daily use.

The takeaway

tmux runs a background server that holds sessions, windows, and panes independently of your terminal, so work survives disconnects and one window can show many shells. Start with tmux new -s name, detach with prefix d, reattach with tmux attach -t name, and use prefix c, %, ", and z to manage windows and panes. Add a short ~/.tmux.conf with mouse support and friendlier splits, and it becomes the backbone of a terminal workflow — especially on remote machines.

The Lycoris Team The Lycoris Team · · 5 min read

How to Use fzf: Fuzzy-Finding in Your Terminal

fzf is a command-line fuzzy finder that filters any list interactively. Here's how to use it for file search, shell history, and git workflows.

#Developer Tools #Command Line #Productivity