What is tmux?
tmux is a terminal multiplexer — it creates and manages multiple terminal sessions from a single window. Think of it as a window manager for your terminal.
The name comes from "terminal multiplexer" or "tmux" for short. It's pronounced "tee-mucks" but many developers just say "tmux".
Why use tmux?
Before tmux, you needed multiple terminal windows or SSH connections to work on different things. tmux gives you:
- Persistent sessions: Programs keep running after you disconnect
- Organization: Group related work into sessions, windows, and panes
- Efficiency: Navigate between contexts without touching the mouse
- Remote work: Start something on a server, detach, and reattach later
Installation
If tmux is installed, you'll see the version number. If not, install it:
- macOS:
brew install tmux - Ubuntu/Debian:
sudo apt install tmux - Fedora:
sudo dnf install tmux - Arch:
sudo pacman -S tmux
Your first session
Start tmux with a named session:
You're now inside a tmux session. The bottom status line shows:
[mysession] 0:bash*
[mysession]is the session name0:bashis window index and name*marks the active window
You're in a normal shell — run commands like ls, vim, or any program. Everything runs inside tmux.
Detach and reattach
The magic happens when you detach — leave tmux without closing programs:
You're back at your normal terminal prompt. Any programs running in the session continue.
List your sessions:
Reattach to pick up where you left off:
This is why tmux is indispensable for remote servers. Start a long-running process (builds, tests, servers), detach, go home, and reattach later.
Prefix key
tmux uses a prefix key to distinguish tmux commands from shell commands. The default is Ctrl-b.
Press Ctrl-b, release both keys, then press the command key.
For example: Ctrl-b d detaches from the session.
Many users remap the prefix key. Ctrl-b is awkward (especially on keyboards where Ctrl requires reaching). Common alternatives: Ctrl-a (GNU screen's default) or Ctrl-space. We'll cover this in Step 7.
Common commands
| Action | Command | Description |
|---|---|---|
| Start session | tmux new -s name | Create new named session |
| Detach | tmux detach or Ctrl-b d | Leave session running |
| List sessions | tmux ls | Show all sessions |
| Attach | tmux attach -t name | Reattach to session |
| Kill session | tmux kill-session -t name | Close session |
Key bindings (prefix = Ctrl-b)
| Key | Action |
|---|---|
d | Detach from session |
? | List all key bindings |
: | Command prompt (enter commands by name) |
Try it
- Create a session:
tmux new -s test - Run a long command:
sleep 300 - Detach:
Ctrl-b d - List:
tmux ls(you'll seetestis still there) - Reattach:
tmux attach -t test(yoursleepis still running!)
Press Ctrl-b ? to see all key bindings. Press q or Esc to exit the help list.
Clean up
When done, exit the session:
Or kill it from outside:
Next: Step 2 → Sessions — Managing multiple sessions