tmux cookbook
Kexin Tang

Tmux

When we use command line tools (CLI), we will open a terminal, and input some commands. This process called “session”. But session is temporary, which means when we close the terminal, the session ends.

How can we keep the session even we close the page?

Using Tmux :)

Tmux will create a new terminal (you can think this is a sub-terminal), and we can run commands inside. When we close the terminal, it will not end the session, just return back to the main terminal, we can connect the sub-terminal again via tmux.

When use tmux?

This is a difficult question. For me, I will use tmux in 2 situations:

  1. I want to show off. You know what I mean, multiple panes in one screen, especially use one pane to run top command, it’s just like hack style.
  2. The task will take a long running time. For instance, the machine learning stuff, you can run it in one session, then go back to working. After one million year, re-connect the session and see error information like “No Module Named xxx” (just don’t ask me why I know that)

cookbook

Command Functionality
tmux new -s <name> create a named session
tmux detach keep the session and go back to main terminal
tmux ls list sessions
tmux attach -t <name> re-connect to session
tmux kill-session -t <name> end session
tmux switch -t <name> switch to session
tmux split-window split up & down
tmux split-window -h split left & right
tmux select-pane -U/D/L/R select up/down/left/right pane
tmux swap-pane -U/D change pane’s size

hot key

hot key functionality
ctrl+d exit and kill session
ctrl+b d tmux detach
ctrl+b ? help
ctrl+b s check all sessions
ctrl+b $ rename session
ctrl+b % split left & right
ctrl+b “ split up & down
ctrl+b x kill session
ctrl+b <arrow key> select pane
ctrl+b ctrl+<arrow key> resize pane
ctrl+b ! make panes into different sessions
ctrl+b :set <command> set properties, eg: :set mouse on to enable mouse control