Right, let’s talk about tmux. You’re probably used to having a dozen terminal tabs open, frantically cd-ing between them, and then your SSH connection drops or your laptop decides it’s time for an unscheduled reboot. Poof. Everything’s gone. Your train of thought, that half-written command, the logs you were tailing—all of it, vaporized. It’s a special kind of digital heartbreak.

tmux is the cure for this. It’s not just a terminal multiplexer; it’s a session saver. It runs on a remote server, completely independent of your local terminal emulator or SSH connection. Your work isn’t tied to a single window or a flaky network. It persists. You can detach from it, go home, reconnect, and it’s all exactly as you left it. It’s the closest thing to time travel we have in the terminal.

The Holy Trinity: Sessions, Windows, and Panes

First, let’s get the hierarchy straight, because if you don’t, you’ll be hopelessly lost. tmux structures things like this:

  • Session: The top-level container. A session is a self-contained workspace, usually dedicated to a single project or task. You might have a webserver session and a database session. You attach to and detach from sessions.
  • Window: A single “tab” within a session. Think of it like a browser tab. Each window occupies the entire screen of your terminal. A session can have multiple windows (e.g., editor, shell, logs).
  • Pane: A split screen within a window. This is where you get that classic hacker-movie look. You can split a window vertically or horizontally to get multiple panes, all running independent shells.

The key is that this entire structure—every session, every window, every pane—is preserved by the tmux server process. Your local terminal is just a viewport into this persistent world.

Starting Your First Session

Enough theory. Let’s get our hands dirty. Fire up your terminal.

# Start a new session named 'my-project'
tmux new-session -s my-project

Boom. You’re inside a tmux session. It will look exactly like a normal terminal, except for that glorious green status bar at the bottom. That’s your new command center. It tells you the session name, the window index, and a host of other info.

Now, let’s say your boss walks in for a “quick chat.” Instead of frantically trying to nohup everything, you simply detach. The magic sequence is your prefix key followed by d. By default, the prefix key is Ctrl+b. Yes, it’s awkward. We’ll fix that later. For now:

  1. Press Ctrl+b (and release).
  2. Then press d.

You’re now back in your original shell, and your session is running happily in the background. To list your sessions:

tmux list-sessions
# my-project: 1 windows (created Tue Oct 24 11:32:15 2023)

And to reattach to it:

tmux attach-session -t my-project

There it is. Right where you left it. No state lost.

Windows: Your Session’s Tabs

Inside your session, you’ll want to manage multiple tasks. That’s what windows are for.

# Create a new window (inside your tmux session, after pressing your prefix key)
Ctrl+b c

A new window appears. The status bar will update to show 0:bash- 1:bash-, indicating you have two windows (index 0 and 1). To switch between them:

Ctrl+b 0  # Switch to window 0
Ctrl+b 1  # Switch to window 1
Ctrl+b n  # Go to the next window
Ctrl+b p  # Go to the previous window

Want to kill the current window? Just exit the shell normally with exit or Ctrl+d. tmux is polite; it won’t keep a window around if there’s no shell in it.

Panes: Divide and Conquer

This is where tmux truly shines. Splitting screens is a joy.

# Split the current pane vertically (right/left)
Ctrl+b %

# Split the current pane horizontally (top/bottom)
Ctrl+b "

You now have multiple panes. To move between them:

Ctrl+b <arrow key>  # Move to pane in that direction
Ctrl+b o            # Cycle to the next pane

Here’s a pro tip: you can resize panes by holding down the prefix key, then pressing Ctrl and an arrow key. Try Ctrl+b, Ctrl+→ to nudge the right pane larger. It’s finicky, but it works.

Want a pane to run a command and then close automatically? Use the tmux command from within the pane itself:

# This pane will run 'htop', and when you exit htop, the pane will vanish.
tmux run-shell -t {pane_id} htop

The {pane_id} is the tricky part; you usually get it from tmux list-panes. It’s a bit clunky, I admit. Sometimes it’s easier to just open a pane and run the command manually.

Taming the Awkward Prefix Key

Let’s address the elephant in the room: Ctrl+b is a terrible default. It’s a two-key chord that requires contorting your left hand across the keyboard. Everyone changes it. The most popular alternative is Ctrl+a, which is right under your pinky and is also the “go to beginning of line” shortcut in bash. But you can’t have two things using Ctrl+a, so we unbind it in tmux and use it as our new prefix.

Edit your ~/.tmux.conf file (create it if it doesn’t exist) and add:

# ~/.tmux.conf
# Change the prefix from Ctrl-b to Ctrl-a
unbind C-b
set-option -g prefix C-a
bind-key C-a send-prefix

# Make sure we can still use Ctrl-a for other things in our shell
set-option -g default-command "bash --rcfile <(echo '. ~/.bashrc; stty -ixon')"

This config does the switch and includes a little hack to ensure Ctrl+a still works normally inside programs like bash. Reload your config with tmux source-file ~/.tmux.conf (or just restart your tmux server by exiting all sessions).

Why This All Matters

It’s not about looking cool (though it does). It’s about preserving your most valuable asset: context. A tmux session becomes a living document of your work on a project. You can leave a tail -f running in a pane, an editor in another, and a database shell in a third. You can detach, and it’s all frozen in time, waiting for you to return. It turns your terminal from a ephemeral, fragile thing into a robust, persistent workspace. It’s one of the few tools that fundamentally changes how you work, for the better. Now go get addicted to it. You’re welcome.