By Tux Harlow — Solnyxus editorial voice. Drafted with AI assistance; reviewed by the team.
You know the moment. The upgrade is forty minutes in, the progress bar has been at 87% for a while, and then the cursor stops blinking. The Wi-Fi hiccuped. The SSH connection is gone, and the shell on the far end went with it, taking the job you started and the scrollback you were going to read. tmux sessions fix this, and they fix it so plainly that you'll be a little annoyed nobody made you learn them sooner.
The trick is simple. tmux runs your shell inside its own server process on the machine, and that process doesn't care whether you're connected. You leave. It keeps going. You come back.
Starting and naming tmux sessions
tmux new -s work
That starts a session called work. Name your sessions. Always. An unnamed session gets a number, and three days later "0", "1" and "4" mean nothing to anyone, least of all you.
tmux ls
That lists every session on the machine.
tmux attach -t work
And that gets you back into work.
tmux new -A -s work
This is the one I'd actually put in muscle memory. It attaches to work if it exists and creates it if it doesn't, so you never have to remember which state you left things in.
The prefix key, and walking away
Every tmux shortcut starts with the prefix, Ctrl-b out of the box. Press it, let go, then press the command key. Not together. Everyone gets this wrong for about a day.
To detach on purpose: Ctrl-b then d. You drop back to your ordinary shell, and the session carries on without you. Here's the lovely part: if the connection dies instead, tmux treats it exactly the same. Nothing is lost. You reconnect, run tmux attach -t work, and the progress bar is right where it was (or, with any luck, finished).
Windows and panes
A session holds windows. A window can be cut into panes. That's the whole model, and these are the keys that drive it:
Ctrl-b ccreates a new window.Ctrl-b nandCtrl-b pmove to the next and previous window.Ctrl-b %splits the current pane left and right.Ctrl-b "splits the current pane top and bottom.Ctrl-bfollowed by an arrow key moves between panes.Ctrl-b zzooms the current pane to fill the window, and pressing it again restores the layout.
Yes, % for a side-by-side split and " for a stacked one is arbitrary. You'll stop noticing within a week. Zoom is the sleeper hit: tail a log in one pane, edit in the other, and blow either one up to full size when you need to actually read it.
Scrolling back
Side note, because this one confuses people: your terminal's scrollbar is useless inside tmux. tmux draws its own screen, so the terminal never sees the history. Scroll with the wheel and you'll get your shell's command history, or nothing at all.
Press Ctrl-b [ to enter copy mode, then use the arrow keys or Page Up. Press q to get out.
And the default history limit is 2000 lines. That's nothing. Follow a busy log for a minute and the interesting part is already gone.
A small tmux.conf
tmux reads ~/.tmux.conf, and since tmux 3.1 it also looks in ~/.config/tmux/tmux.conf if you like your home directory tidy. Three lines go a long way:
set -g mouse on
set -g history-limit 50000
set -g base-index 1
The first turns on the mouse: click a pane to select it, drag a border to resize, scroll with the wheel. The second raises the scrollback to 50,000 lines, which is what that 2000 should have been. The third numbers windows from 1, so they line up with the number row instead of starting over by the backtick.
Reload it without restarting anything:
tmux source-file ~/.tmux.conf
Ending sessions
tmux kill-session -t work
That ends work and everything running inside it, so make sure you mean it. Typing exit in the last pane of the last window does the same thing, more politely.
When sessions vanish at logout
One gotcha. Some systems are set to kill a user's processes at logout, through systemd-logind's KillUserProcesses=yes setting in logind.conf. If your tmux sessions disappear every time you log out, that's the first place to look. Most distributions ship it set to no, so if you're hitting this, someone chose it.
So: next time you SSH somewhere to run anything that takes longer than a coffee, type tmux new -A -s work first. The Wi-Fi will still hiccup. It just won't matter anymore.
Linux
More like this
Linux
entr and watch: Make Your Terminal Rerun Things So You Don't Have To
Save, switch window, press up, press Enter, squint. Save, switch window, press up... Stop. entr reruns your command whenever a file changes, and watch reruns it on a timer. Two tiny tools, a thousand saved keystrokes.
Linux
ripgrep: grep, But It Drank Three Espressos and Read Your .gitignore
grep is a legend. It's also happy to search all 80,000 files in node_modules while you wait. ripgrep searches only what matters, very quickly, with sensible defaults. The flags worth knowing, and when old grep still wins.
Linux
Linux Terminal Toys (and the Surprisingly Useful Tools Hiding Among Them)
A talking cow, a train that punishes typos, the Matrix in your terminal, and hidden among them, six genuinely useful tools you'll keep long after the novelty wears off. A toy box for Linux nerds.