tmux is a "terminal multiplexer" — a tool that lets one terminal window hold many shells, and (more importantly) keeps those shells running when you disconnect. If you've ever lost work because your SSH session dropped, tmux is the cure.
This is the friendly tour: what you need to do useful things, not every feature ever.
Install
sudo apt install tmux # Debian / Mint / Ubuntu
sudo pacman -S tmux # Arch / Manjaro
sudo pkg install tmux # FreeBSD
Start a session
tmux
The screen looks almost the same as before, but now there's a green status bar at the bottom. That's your sign tmux is wrapping the terminal.
The one shortcut to memorise: the prefix
Every tmux command starts with the prefix key: Ctrl+b. You press it, let go, then press a second key.
Notation throughout this guide: Ctrl-b c means "hit Ctrl-b, release, hit c."
Survive a disconnect
The killer feature. Imagine you're running a long backup over SSH and your laptop's battery dies:
- Without tmux: the backup is interrupted halfway. Everything you were doing is gone.
- With tmux: the session keeps running on the server. Next time you SSH back in, you reattach and it's as if nothing happened.
Detach on purpose: Ctrl-b d. You drop back to your normal shell. Your work isn't lost — it's parked.
List your parked sessions:
tmux ls
Reattach to the most recent one:
tmux attach
Reattach to a specific one:
tmux attach -t 0
The four things tmux organises
- Session — one tmux "instance," persistent.
- Window — like a tab inside a session.
- Pane — a split inside a window.
- Status bar — the line at the bottom showing all of the above.
Windows: tabs without a mouse
Ctrl-b c # create a new window
Ctrl-b n # next window
Ctrl-b p # previous window
Ctrl-b 0..9 # jump to window number 0-9
Ctrl-b , # rename current window
Ctrl-b & # kill current window (asks first)
Panes: split a window in two
Ctrl-b % # split vertically (side by side)
Ctrl-b " # split horizontally (top / bottom)
Ctrl-b arrow # move between panes
Ctrl-b z # zoom current pane fullscreen (press again to un-zoom)
Ctrl-b x # close current pane (asks first)
Tip: split once for code, split again for the log tail, zoom in on the one you're editing.
Copy mode: scroll back and copy text
Mouse-free scrolling. Ctrl-b [ enters copy mode. Then:
- Arrow keys / Page Up / Page Down to navigate.
- Space to start a selection, Enter to copy.
- q to leave copy mode.
Paste back with Ctrl-b ].
Name your sessions
tmux new -s deploy
Now it shows up as "deploy" in tmux ls and you can reattach with tmux attach -t deploy. Much nicer than 0, 1, 2.
A two-line ~/.tmux.conf to taste-test
Drop this in your home directory and tmux feels nicer:
# ~/.tmux.conf
set -g mouse on
set -g history-limit 10000
Now you can click between panes and scroll with the wheel, and the scrollback is 10k lines instead of the default 2k.
Reload without restarting: Ctrl-b :, then type source-file ~/.tmux.conf and Enter.
Closing thought
Don't try to learn every shortcut. The five worth memorising:
- Ctrl-b d — detach
- Ctrl-b c — new window
- Ctrl-b n / p — next / previous window
- Ctrl-b % / " — split pane
- Ctrl-b z — zoom
Everything else you can look up the day you need it.