Tmux Cheat Sheet: Essential Commands
This cheat sheet covers the essential tmux commands for managing sessions, windows, and panes. You’ll learn the default key bindings and common command-line equivalents, enabling you to work more efficiently in the terminal.
What Is Tmux?
Tmux is a terminal multiplexer that lets you run multiple terminal sessions within a single window. It keeps these sessions alive even when you disconnect, so you can reattach later. This is especially useful for remote work over SSH, where a dropped connection would otherwise kill your running processes.
Getting Started: Prefix Key
Most tmux commands are triggered by a prefix key, which by default is Ctrl-b. You press the prefix, release it, then press the command key. For example, to create a new window, press Ctrl-b then c.
You can change the prefix in your ~/.tmux.conf file, but the default works for most people. If you use tmux heavily, consider remapping it to Ctrl-a to avoid conflicts with other tools.
Session Management
Sessions are the top-level containers in tmux. Each session can have multiple windows, and each window can have multiple panes. Start a new session with tmux new -s session_name, and detach from it with Ctrl-b d. To list all sessions, use tmux ls. Reattach to a session with tmux attach -t session_name.
- New session:
tmux new -s name - Detach:
Ctrl-b d - List sessions:
tmux ls - Attach:
tmux attach -t name - Kill session:
tmux kill-session -t name
Window Management
Windows are like tabs in a browser. You can create, switch, and close windows independently. The default key bindings are:
- Create new window:
Ctrl-b c - Next window:
Ctrl-b n - Previous window:
Ctrl-b p - List windows:
Ctrl-b w - Rename window:
Ctrl-b , - Close window:
Ctrl-b &
You can also jump directly to a window by number: Ctrl-b 0 for window 0, Ctrl-b 1 for window 1, and so on.
Pane Management
Panes split a window into multiple rectangular regions, each running its own shell. This is great for side-by-side editing or monitoring logs while coding.
- Split horizontally:
Ctrl-b % - Split vertically:
Ctrl-b " - Move between panes:
Ctrl-b arrow keys - Close pane:
Ctrl-b x - Toggle pane layout:
Ctrl-b space
To resize a pane, hold Ctrl-b and press the arrow keys. This can take some practice to get the hang of.
Copy Mode and Scrolling
To scroll up in a pane, enter copy mode with Ctrl-b [. Then use the arrow keys or Page Up/Page Down to navigate. To copy text, press Space to start selection, move to the end, and press Enter to copy. Paste with Ctrl-b ].
This is particularly useful when you need to review output that scrolled off the screen or copy a command from a previous session.
Common Troubleshooting
If tmux behaves unexpectedly, check the following:
- Prefix not working: Make sure you’re not in copy mode. Press
qto exit copy mode. - Session not found: Use
tmux lsto see active sessions. If you killed it, it’s gone. - Pane too small: Resize with
Ctrl-b :resize-pane -D(or-U,-L,-R). - Stuck in zoom: Press
Ctrl-b zto toggle zoom on a pane.
Frequently Asked Questions
How do I exit tmux without killing my sessions?
Press Ctrl-b d to detach. Your session keeps running in the background. To reattach later, use tmux attach.
Can I share a tmux session with another user?
Yes, but it requires socket permissions. Start tmux with tmux -S /tmp/shared and set the socket permissions so the other user can read/write. They can then attach with tmux -S /tmp/shared attach.
How do I make tmux use my default shell?
Set the default-shell option in your ~/.tmux.conf file. For example: set -g default-shell /bin/zsh.
What is the difference between tmux and screen?
Both are terminal multiplexers, but tmux is more modern and supports vertical splits out of the box. Screen requires configuration for vertical splits. Tmux also has a client-server model that allows more flexible scripting.
Why does my tmux status bar show a different time than my system?
Tmux has its own clock format. You can change it with set -g clock-mode-style 24 for 24-hour format or 12 for 12-hour. The status bar time updates every 15 seconds by default.
How do I reload my tmux config without restarting?
Press Ctrl-b : to enter command mode, then type source-file ~/.tmux.conf and press Enter. Alternatively, add bind r source-file ~/.tmux.conf to your config to reload with Ctrl-b r.
Related
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.