The default
--help
command withtmux
is not super helpful. I would recommendman tmux
, this cheatsheet, or the tmux wiki, as alternatives.
tmux - Common Commands
Here are some of my most-used commands
Command | Description |
---|---|
tmux new -s {SESSION_NAME} |
Create a named session |
tmux attach -t {SESSION_NAME} |
Attach to a named session |
tmux ls |
List sessions |
exit |
If run within a session, will exit (and kill!) the current session |
tmux kill-session |
Kills the current session you are in, or use -t to kill specific ones. |
tmux info |
Show all info |
CTRL + b |
The main hotkey combo to enter the tmux command mode - i.e., what you need to press first, before a secondary hotkey. |
CTRL + b , d |
Detach from the current session |
CTRL + b , [ |
Enter copy mode. Use ESC to exit |
CTRL + b , s |
Interactive session switcher, from inside an active session. Faster than detaching, listing, and then re-attaching, plus you can see a preview before switching. |
tmux kill-server |
Kill the entire tmux server |
tmux start or tmux start-server |
Start the tmux server |
If you run into issues starting tmux, with a server exited unexpectedly error, try deleting
tmux-*
folders from within/tmp
first
tmux Configuration
tmux Config File - .tmux.conf
You can often configure tmux settings via the tmux command prompt (entered via CTRL + B
, :
), but for portability and easier management, it can preferable to store configuration settings in a dedicated file. Tmux supports this by default via a file at ~/.tmux.conf
(but you can also explicitly pick a different file location and name if you want).
Here are some quick notes on the usage of this configuration file:
- By default, tmux only reads & loads the config file once, on service startup. If you make changes and want to see them reflected in tmux, you need to do one of the following
- Use the
tmux source-file
command- E.g.,
tmux source-file ~/.tmux.conf
- You should run this outside of tmux itself (not inside a session). You can use this inside an existing tmux session and will take effect. However, it will only take effect for that specific session if you do that, as opposed to all.
- You will also need to detach and re-attach to sessions to read the change, or also run the command inside each session
- E.g.,
- Completely restart the tmux service (different from restarting a session)
- Use the
- Comments are allowed, and use the standard shell
#
prefix
Enabling Scroll in tmux
You can use CTRL + B
, then [
to enter copy mode, then scroll or key around (and copy text if you wish), using ESC
to exit the mode.
You can also do CTRL + B
, :
, set -g mouse on
to turn on mouse mode (or do so through your tmux config file). However, this tends to interfere with copy-and-pasting and generally is not a super smooth experience.
tmux - Reading into the Scrollback Buffer
# From within a tmux pane
tmux capture-pane -pJS -${number_of_past_lines} > file.out
# From outside tmux pane
tmux capture-pane -t ${pane_id} -pJS "-${number_of_past_lines}" > file.out
Tmux Tips and Tricks
- You can use
tmux display-message
to temporarily show a message in the tmux status bar