Tmux is a terminal multiplexer. But every terminal into Tmux is pseudo-terminal.

Basic conceptions

All configuration can be modified into ~/.tmux.conf. For newer edition, it can be put into ~/.config/tmux/.

Server
│
├── Session
│     ├── Window
│     │      ├── Pane
│     │      └── Pane
│     │
│     └── Window
│
└── Session
  • Server: A Tmux service for managing all sessions into it. Type tmux enable the service and run it.

  • Session: A whole and complete working environment. Sessions are completely independent of each other. Keywords: create/ detach/ attach.

  • Window: windows are working under sessions. It is similar to the web browser’s tab.

  • Pane: Split one window into differnet parts.

Official Structure

https://github.com/tmux/tmux/wiki/Getting-Started

All commands must use prefix + specific character. Ctrl + b is the common prefix in every system. Use C-b or P for short.

Status Line

https://github.com/tmux/tmux/wiki/Getting-Started

Sessions

tmux new-sesson
tmux new                #create a session with default name 0

tmux new -s work        # new named session -s: specified
tmux ls                 # list sessions

tmux a
tmux attach             # attach to the most recently used sessioin
tmux attach -t work     # reattach to the session named work
tmux kill-session -t work
tmux rename-window work # rename the current window
KeysAction
P $rename the current session

Detach from inside: P d.

Window

Create

Create a window must in a specific session

tmux new-window 
tmux neww               #create a new window 

tmux neww -d            # create a new window but doesn't make it the current window
tmux neww -n windowname # create a new window named windowname
tmux neww -t 999        #create a new window with index 999

Operations

KeysAction
P &kill the current window

Panes

KeysAction
prefix %split vertically (left and right)
prefix "split horizontally (up and down)
prefix arrowmove between panes
prefix zzoom / unzoom current pane
prefix xkill pane
P *create a floating pane
P @change the current pane to the floating pane
P up/down/left/rightmove focus to other pane
P mmark the pane for swap
P { or P }rotate the pane/swap
P spacemodify the layout
tmux swap-pane      #swap the current pane with marked one

Choosing sessions, windows and panes

KeysAction
P sshow the list of sessions into tree architecture
P wextend all contents into session list
xworks in the tree view. Killing target window

Copy mode

prefix [ to enter, q to quit. Vi keys if setw -g mode-keys vi.

Why bother

SSH into the lab box, start a long experiment inside tmux, close the laptop, reattach from anywhere. The experiment never notices.