This guide takes the tmux section of Shell Essentials deeper. There you met the idea and a handful of keys; here you learn how to actually live inside tmux.
You need tmux installed first, and none of the big three distros ship
it by default:
$ sudo apt install tmux # Ubuntu
$ sudo dnf install tmux # Fedora
$ sudo pacman -S tmux # Arch
Everything here was checked on tmux 3.6 (Ubuntu 26.04) and tmux 3.7c (Fedora 44, Arch). The two versions behave identically throughout.
What tmux actually does
In an ordinary terminal, your shell lives inside the terminal program. Close the window, lose the shell. Lose the SSH connection, lose the shell. Anything that shell was running dies with it.
tmux puts a layer in between. Your programs run inside a tmux server process that owes nothing to the visible terminal; the terminal merely shows a view of what the server holds. Detach the view and the server keeps every program running. Attach a new view later, from a different connection if you like, and everything sits where you left it.
That is the entire trick.
Sessions
Start one:
$ tmux new -s work
The screen clears and a status line appears along the bottom edge. That line is tmux; from now on it tells you which session and window you are in, and later it will carry the messages tmux wants you to see.
When you want to leave, press Ctrl+B, release, then press d:
[detached (from session work)]
You are back in the plain terminal, and the session carries on without
you. tmux ls proves it:
$ tmux ls
work: 1 windows (created Sat Aug 29 21:07:43 2026)
Come back from anywhere:
$ tmux attach -t work
You land where you detached, scrollback intact. When the work is done
and you want the slot gone, tmux kill-session -t work ends it. With
no sessions left, tmux ls answers:
no server running on /tmp/tmux-0/default
That sounds more dramatic than it is. It just means there is nothing left to list.
tmux new -d -s build creates a
session without switching to it. Handy for parking a long job in its
own session from a script, or for setting up a workspace in advance.
The prefix key
Almost everything in tmux is two keystrokes: Ctrl+B, released, then
one more key. That first combo is called the prefix, and it exists so
tmux can tell its own commands apart from your typing. A bare d types
the letter d. Ctrl+B d detaches. Every shortcut in this guide is
written the same way: prefix first, then the key.
Windows
A session starts with one window. Ctrl+B c opens another: a full,
blank screen with its own shell. Step through them with Ctrl+B n
(next) and Ctrl+B p (previous), like tabs in a browser. The status line keeps the windows
numbered, and the current one is marked with *.
Windows get names. Press Ctrl+B , and tmux shows a prompt:
(rename-window) work
Watch out here: the current name is already typed in, and whatever you
type gets appended to it. For a fresh window that pre-filled name is
usually just bash, the program running inside. Backspace over it
first, then type the new one. It sticks, which
matters once you have several windows open and no longer remember
which one holds htop.
Closing a window is Ctrl+B &. tmux asks before it kills anything:
kill-window work? (y/n)
y confirms, and the window goes, with everything running in it.
Panes
Where a window is a whole topic, panes divide one window into regions.
Ctrl+B % splits with a vertical divider, giving you two panes side by
side. Ctrl+B " splits with a horizontal divider and stacks them.
Move between panes with Ctrl+B o, which cycles through them and wraps
back around. The arrow keys work too: Ctrl+B Left, Ctrl+B Right,
and so on move toward whichever pane sits in that direction.
Two more keys earn their keep. Ctrl+B z zooms the current pane to
fill the entire window; press it again and the other panes come back.
Ctrl+B x closes the current pane; tmux asks first:
kill-pane 0? (y/n)
y, and the pane is gone. The number in the prompt is the index of the
pane tmux is about to kill, nothing more.
Surviving the disconnect
You SSH to a rented server, run tmux new -s download, and start
transferring a large file. Hours pass. The connection drops: hotel
Wi-Fi, a rebooted router — pick your villain.
Without tmux, the transfer died with the connection. With tmux, the
recovery is boring. Reconnect, tmux attach -t download, and there is
your transfer, still running, with every line of output since you left
stacked up in the scrollback. The session never noticed you were gone.
This is the difference between tmux and nohup from chapter 13.
nohup is for jobs you fire and forget about. tmux is for jobs you
intend to come back to, which in practice is most of them.
Scrollback
tmux draws the whole screen itself, so the scrolling your terminal
program usually provides does not reach inside it. There is a tmux way.
Press Ctrl+B [ and the cursor enters copy mode, with a position
indicator appearing on the status line:
[0/79]
That is: line 0 of 79 buffered. PageUp moves up one page per
press, and the counter follows along. q leaves copy mode and drops
you back at the prompt.
Pick this habit up early. Scrollback is where the output of a long build lives after it scrolled off the screen. New tmux users reach for their old scrolling habits here, and nothing happens.
Reading is half the skill; taking text out is the other half. Copy mode
is also a selection mode. With the cursor on the first character you
want, press Ctrl+Space to start a selection, move to the end of it,
then press Alt+W — the selected text goes into a tmux buffer and copy
mode closes. Paste it anywhere with Ctrl+B ]. These are the default
keys; if your setup is configured vi-style, the selection keys are
Space and Enter instead, and everything downstream is the same.
The buffer is a real object you can inspect:
$ tmux list-buffers
buffer0: 20 bytes: "root@linuz-ubuntu:~#"
Pasting drops the buffer’s contents into the pane at the cursor, which is how output travels from one pane to its neighbour without a mouse.
A two-line config
tmux reads ~/.tmux.conf when its server starts. Create it with
nano ~/.tmux.conf if it does not exist yet. Two lines cover the
usual settings:
set -g mouse on
set -g history-limit 5000
(The -g on both lines sets the option globally, for every session
rather than just this one.)
mouse on switches on tmux’s mouse support for people who want to
click and scroll in panes. This guide stays keyboard-only, so treat it
as a bonus rather than a requirement. Every key above works either way.
history-limit sets how many lines of scrollback each pane keeps. The
default is 2000, and 5000 gives a long build room to breathe.
If no server is running yet, your first tmux new after saving simply
has both settings in effect. To apply the file to a server that is
already running:
$ tmux source-file ~/.tmux.conf
Where you are now
You now have the working core of tmux. Power users go much deeper, and nearly all of that depth can wait until you need it.
Chapter 13 shows where tmux sits among the rest of the shell toolkit, and the cheat sheet keeps the keys on one line each. When you outgrow this guide, the full tmux manual documents every command and key binding, and the ArchWiki tmux article collects the configurations and fixes for the power-user stage.