Tmux learning note

Tmux is a terminal multiplexer which allows multiple sessions with windows, panes, and more.

Basic usage

启动&退出

1
tmux

退出:Ctrl+d或显示输入exit命令

前缀键

默认的前缀键是ctrl + b

如:帮助命令的快捷键是:Ctrl + b ?,按ESC或q键退出

会话管理

Start a new named session

1
tmux new -s {session-name}

Detach from the current session (inside a tmux session)

1
tmux detach

or using shortcut: CTRL + b d

List existing sessions

1
2
3
tmux ls 
# or
tmux list-session

Attach to session

1
2
3
4
# using session id
tmux attach -t 0
# using session name
tmux attach -t {session-name}

Kill session

1
2
3
4
# using session id
tmux kill-session -t 0
# using session name
tmux kill-session -t {session-name}

Switch session

1
2
3
4
# using session id
tmux switch -t 0
# using session name
tmux switch -t {session-name}

or Ctrl-B w to switch between sessions and windows

Rename session

1
tmux rename-session -t 0 {new-name}

session shortcuts

  • Ctrl-B d: detach from current session
  • Ctrl-B s: list all session
  • Ctrl-B $: rename current session
1
2
3
4
5
6
7
8
- Detach from the current session (inside a tmux session):
Ctrl-B d

- Create a new window (inside a tmux session):
Ctrl-B c

- Switch between sessions and windows (inside a tmux session):
Ctrl-B w

Pane

Tmux can split window into multiple panes.

split pane

1
2
3
tmux split-window
#
tmux split-window -h

select pane

1
2
3
4
5
# to up
tmux select-pane -U
tmux select-pane -D
tmux select-pane -L
tmux select-pane -R

swap position of panes

1
2
3
# move current pane to up
tmux swap-pane -U
tmux swap-pane -D

pane shortcuts

  • Ctrl-b % : split-pane horizontally
  • Ctrl-b " : split-pane vertically
  • Ctrl-b <arrow key> : move cursor to other pane
  • Ctrl-b ; : switch cursor to previous pane
  • Ctrl-b o : switch cursor to next pane

Window Management

start a new window

1
tmux new-window [-n {window-name}]

switch to a window

1
2
tmux select-window -t {window-number}
tmux select-window -t {window-name}

rename

tmux rename-window

shortcut for windows

  • Ctrl-b c: start a new window
  • Ctrl-b p: switch to previous window
  • Ctrl-b n: switch to next window
  • Ctrl-b {name}: switch to a window with designated number
  • Ctrl-b w: select window from list
  • Ctrl-b ,: rename window