Sessions
| Task | Command or key |
|---|---|
Attach to work, or create it | tmux new -A -s work |
| New session in the background | tmux new -d -s work |
| List sessions | tmux ls |
| Attach | tmux attach -t work |
| Detach and leave it running | Ctrl+b d |
| Rename the session | Ctrl+b $ |
| Choose a session from a list | Ctrl+b s |
| End a session | tmux kill-session -t work |
| End all sessions | tmux kill-server |
| Check whether a session exists, for scripts | tmux has-session -t work |
Windows
| Task | Key |
|---|---|
| New window | Ctrl+b c |
| Next, previous | Ctrl+b n, Ctrl+b p |
| Go to window 0 | Ctrl+b 0 |
| Last window used | Ctrl+b l |
| Rename | Ctrl+b , |
| Choose from a tree of all windows | Ctrl+b w, and q to leave |
Close, after confirming with y | Ctrl+b & |
Panes
| Task | Key or command |
|---|---|
| Split side by side | Ctrl+b % |
| Split top and bottom | Ctrl+b " |
| Move between panes | Ctrl+b and an arrow key |
| Next pane | Ctrl+b o |
| Zoom in and out | Ctrl+b z |
| Show pane numbers | Ctrl+b q |
| Turn a pane into its own window | Ctrl+b ! |
Close, after confirming with y | Ctrl+b x |
| Resize by 5 cells to the left | tmux resize-pane -L 5 |
| Swap with the next pane | tmux swap-pane -D |
| Equal columns | tmux select-layout even-horizontal |
Scrolling and copying
| Task | Key or command |
|---|---|
| Enter copy mode to scroll | Ctrl+b [ |
| Leave copy mode | q |
| Save the last 3000 lines to a file | tmux capture-pane -p -S -3000 > out.txt |
Other useful keys
| Task | Key |
|---|---|
| List all key bindings | Ctrl+b ? |
| Type a tmux command | Ctrl+b : |
| Show a clock | Ctrl+b t |
Scripting from outside
Every key has a command behind it, so you can drive tmux from a script or over SSH:
tmux new -d -s work
tmux new-window -t work -n logs
tmux split-window -h -t work
tmux send-keys -t work 'echo hello' Enter
tmux capture-pane -p -t work
tmux kill-window -t work:logs
From your own machine, ssh -t user@server tmux new -A -s work goes straight into a session. The -t is needed because tmux wants a terminal.
Configuration
Settings go in ~/.tmux.conf. These two are common:
set -g mouse on
set -g history-limit 50000
Load the file without restarting:
tmux source-file ~/.tmux.conf
Options set while tmux runs last until the tmux server ends. history-limit applies to new panes, not to existing ones.
Messages you may see
| Message | Meaning |
|---|---|
no server running on /tmp/tmux-1000/default | No sessions exist, for example after a reboot |
can't find session: work | That name does not exist. Check tmux ls |
To learn why sessions survive a dropped connection and what they do not survive, read how to keep SSH sessions alive with tmux.
If you are still choosing between the two tools, see tmux vs screen.
Questions
How do I scroll up in tmux?
Press Ctrl+b [ to enter copy mode, then use the arrow keys or Page Up. Press q to leave. With set -g mouse on in ~/.tmux.conf, the mouse wheel scrolls too.
How do I detach from tmux without ending the session?
Press Ctrl+b d. The session and its programs keep running, and tmux attach -t work brings it back.
How do I close a tmux session?
Run tmux kill-session -t work, or type exit in its last shell. tmux kill-server ends every session.
How do I change the tmux prefix to Ctrl+a?
Add set -g prefix C-a, unbind C-b and bind C-a send-prefix to ~/.tmux.conf, then run tmux source-file ~/.tmux.conf. Press Ctrl+a twice when a program needs Ctrl+a itself.