Skip to content

~/avetyan.com/cheatsheets

Cheat sheets

tmux cheat sheet

Keep SSH sessions alive and split your terminal with tmux: sessions, windows, panes, copy mode, the commands I use and a minimal config.

2 min read


Prefix is Ctrl-b by default. Press it, let go, then press the key.

Sessions

bash
tmux new -s deploy                      # new named session
tmux ls
tmux attach -t deploy                   # or: tmux a
tmux new -As deploy                     # attach, or create if missing
tmux kill-session -t deploy
KeysAction

Windows

KeysAction

Panes

KeysAction

Copy mode

KeysAction

With setw -g mode-keys vi, use v to select and y to copy.

Commands

bash
tmux send-keys -t deploy 'tail -f /var/log/app.log' Enter
tmux new -d -s backup 'rsync -a /data /backup'          # start detached
tmux capture-pane -pS -3000 -t deploy > pane.log        # save scrollback
tmux setw synchronize-panes on          # type in every pane at once

Prefix : opens the command prompt inside tmux, for the same commands without the tmux prefix.

Share a session

bash
tmux -S /tmp/pair new -s pair
chmod 770 /tmp/pair; chgrp ops /tmp/pair
tmux -S /tmp/pair attach -t pair        # the other person, in group ops

Minimal config

~/.tmux.conf
set -g mouse on
set -g history-limit 50000
set -g base-index 1
setw -g pane-base-index 1
set -g renumber-windows on
setw -g mode-keys vi
set -sg escape-time 10
bind r source-file ~/.tmux.conf \; display "reloaded"
bind | split-window -h -c "#{pane_current_path}"
bind - split-window -v -c "#{pane_current_path}"

Keep in mind

  • Run long jobs on a server inside tmux, so a dropped SSH connection doesn’t kill them.
  • Nested tmux (local and remote): press the prefix twice to reach the inner one.
  • With mouse on, hold Shift to select text with the terminal’s own selection.

Comments

Sign in with Google, GitHub or Facebook to comment.

Loading comments…