tmux cheatsheet and good practices
tmux keeps terminal sessions running when you detach or lose an SSH connection. It also gives you tabs and split terminals in one window.
- Session: a workspace, usually one per project or server task.
- Window: a tab inside a session.
- Pane: a split terminal inside a window, with its own shell or program.
Install and get started
Install with your distribution's package manager:
# Debian / Ubuntu
sudo apt update
sudo apt install tmux
# Fedora / RHEL
sudo dnf install tmux
# Arch Linux
sudo pacman -S tmux
Start a named session:
Run commands normally. Press Ctrl+b, release both keys, then press d to detach. Your shells and programs keep running. Return with:
Throughout this cheatsheet, Prefix means Ctrl+b, followed by the listed key. These are the default bindings; custom configurations can change them. For symbols such as % and ", use Shift as required by your keyboard layout.
Keyboard cheatsheet
Sessions and help
| Shortcut | Action |
|---|---|
Prefix d |
Detach and leave the session running |
Prefix s |
Choose a session |
Prefix $ |
Rename the current session |
Prefix w |
Browse sessions, windows, and panes |
Prefix ? |
Show key bindings |
Prefix : |
Open the tmux command prompt |
At the tmux command prompt, omit the tmux executable name. For example, enter list-sessions and press Enter.
Windows
| Shortcut | Action |
|---|---|
Prefix c |
Create a window |
Prefix , |
Rename the window |
Prefix n / p |
Next / previous window |
Prefix 0–9 |
Select a window by number |
Prefix l (lowercase L) |
Return to the last window |
Prefix & |
Kill the current window, after confirmation |
Panes
| Shortcut | Action |
|---|---|
Prefix % |
Split into left and right panes |
Prefix " |
Split into top and bottom panes |
| Prefix arrow key | Move to the pane in that direction |
Prefix o |
Move to the next pane |
Prefix ; |
Return to the last active pane |
Prefix q |
Show pane numbers; press a number while visible to select it |
Prefix z |
Zoom the active pane / restore the layout |
Prefix Space |
Cycle pane layouts |
Prefix Ctrl+arrow |
Resize the pane by one cell |
Prefix Alt+arrow |
Resize the pane by five cells |
Prefix { / } |
Swap with the previous / next pane |
Prefix ! |
Move the pane into its own window |
Prefix x |
Kill the pane, after confirmation |
If your terminal intercepts resize shortcuts, use Prefix : and enter resize-pane -R 5 instead. Other directions are -L, -U, and -D.
Use exit in an idle shell to close its pane normally. Closing the last pane closes the window; closing the last window ends the session. Detach with Prefix d when you want to come back later.
Shell commands
Run these at a normal shell prompt:
| Command | Action |
|---|---|
tmux ls |
List sessions |
tmux new -s work |
Create and attach to a named session |
tmux new -As work |
Attach to work, or create it if missing |
tmux attach -t work |
Attach to an existing session |
tmux attach -d -t work |
Attach and detach other clients from that session |
tmux rename-session -t work project |
Rename a session |
tmux switch-client -t work |
Switch sessions from inside tmux |
tmux new-window -t work -n logs |
Create a named window in a session |
tmux list-panes -a |
List panes across all sessions |
tmux kill-session -t '=work' |
Destroy exactly the session named work and its unshared windows |
kill-session closes the session's terminals and can terminate running work. tmux kill-server destroys all sessions on that tmux server; it is not a detach or configuration-reload command.
Scroll, search, copy, and paste
Press Prefix [ to enter copy mode. Prefix Page Up enters copy mode and scrolls up one page. Once inside copy mode, the following keys do not need the prefix:
| Action | Emacs mode | Vi mode |
|---|---|---|
| Move cursor | Arrow keys | Arrow keys or h, j, k, l |
| Page up / down | Page Up / Page Down |
Ctrl+b / Ctrl+f |
| Search backward | Ctrl+r |
? |
| Search forward | Ctrl+s |
/ |
| Start selection | Ctrl+Space |
Space |
| Copy selection and leave copy mode | Alt+w |
Enter |
| Leave copy mode | Esc |
q |
Enter the search text and press Enter. tmux normally uses Emacs mode, but can select Vi mode when VISUAL or EDITOR contains vi. Check with tmux show-options -gw mode-keys; the configuration below explicitly selects Vi mode.
Outside copy mode:
- Prefix
]pastes the most recent tmux buffer. - Prefix
=opens the buffer chooser. tmux show-bufferprints the latest buffer in your shell.
tmux paste buffers are separate from your desktop clipboard. System clipboard integration depends on your terminal and settings, especially over SSH. With mouse mode enabled, many terminals let you hold Shift while selecting text to use the terminal's own selection instead.
A practical SSH workflow
Start tmux on the remote host so the work stays there if SSH disconnects:
- Rename the first window with Prefix
,toshell. - Create a second window with Prefix
c, rename itlogs, and runjournalctl -fthere. - Return to
shellwith Prefixpand run your maintenance commands. - Detach with Prefix
d, thenexitthe SSH shell when finished for now. - Reconnect with SSH and run
tmux attach -t maintenanceto resume.
Starting tmux locally and running SSH inside it only preserves the local terminal; it does not protect remote commands from an SSH disconnect.
Small, useful configuration
Add the settings you want to ~/.tmux.conf on the machine running tmux:
# Click to select panes, drag borders, and scroll with the mouse.
set -g mouse on
# Keep more scrollback for newly created panes (lines per pane).
set -g history-limit 50000
# Use the Vi copy-mode keys from the table above.
setw -g mode-keys vi
# Keep window names you set manually.
setw -g allow-rename off
setw -g automatic-rename off
# Open windows and splits in the active pane's working directory.
bind c new-window -c "#{pane_current_path}"
bind % split-window -h -c "#{pane_current_path}"
bind '"' split-window -v -c "#{pane_current_path}"
# Prefix r reloads this file.
bind r source-file ~/.tmux.conf
Reload from a shell inside a running tmux session:
tmux reads its configuration automatically when its server first starts. Starting another session on an existing server does not reload the file. Increasing history-limit applies to new panes, not the scrollback allocation of existing ones.
Good practices
- Use meaningful names. Sessions such as
project-apiormaintenanceand windows such aseditor,shell, andlogsare easier to find than numbers alone. - Use windows for different tasks and panes for related views. A shell beside its logs is useful; too many tiny panes are not. Prefix
zgives a pane temporary breathing room. - Detach to preserve work. tmux survives terminal and SSH disconnections while its server and host remain running. It does not survive a host reboot or protect against processes being stopped by logout policies.
- Use a service manager for services. tmux is useful for interactive maintenance and development. Use systemd for programs that need startup at boot, restarts, and managed logs.
- Keep important output in real logs. Scrollback is finite and disappears when its pane is destroyed. To snapshot the current pane's retained history from a shell inside that pane, run
tmux capture-pane -p -S - > ~/tmux-capture.txt; this is not continuous logging and overwrites that file. - Run tmux as your regular user. Use
sudofor individual commands when needed. Reattach as the same user on the same host;sudo tmuxuses a separate server and session list. - Switch sessions instead of nesting them. Use Prefix
sortmux switch-client -t work. If local and remote tmux are deliberately nested with the default prefix, pressCtrl+b, thenCtrl+b, then the command key to send a command to the inner tmux. - Keep pane synchronization deliberate. Prefix
:followed bysetw synchronize-panes onbroadcasts input to panes in the current window that are not in a mode. Turn it off withsetw synchronize-panes offas soon as the shared task is done. - Keep configuration small and version-controlled. Learn the default prefix and a few shortcuts first, then add bindings you actually use.
Troubleshooting and reference
| Symptom | Check |
|---|---|
no server running or no sessions |
Confirm the host and user, then create a session with tmux new -s work |
| Output appears frozen while scrolling | Leave copy mode with q in Vi mode or Esc in Emacs mode |
| A shortcut behaves differently | Inspect active bindings with Prefix ? or tmux list-keys |
| A setting did not apply | Reload the configuration and check any error messages; some options only affect new panes |
| Display looks garbled after resizing | Try tmux refresh-client from a shell inside tmux |
Use tmux -V to check your installed version and man tmux for its matching manual. The official getting started guide has more examples.