Tmux in Daily Usage

Abstract

Tmux is a commond line based tool that enable you to open multiple windowns, tabs or sessions in one terminal. With that, you can work on multiple tasks efficiently as you can separate them in different tmux sessions.

Content

In following part, we may use a command or keyboard-shortcut to achieve our request.

  • command usually starts with tmux, which would input to terminal.
  • keyboard-shortcut usually starts with ctral+b, which would only work when you’re in a terminal window that attaching session.

Keep in mind that the both attached&detached session would still keep running the program. It’s quite useful when you’re working on a remote server, the program would keep running in detached session even though you may disconnected with remote server.

A session would have an unique session-idx, it’s assigned when created, and is self increased (start by 0).

  • start a new session: tmux or tmux new -s <session-name>.
  • list all existing sessions: tmux ls or tmux list-session or ctrl+b s.
  • detach existing session: tmux detach or ctrl+b d.
  • attach existing session: tmux attach -t session-idx or tmux attach -t session-name.
  • kill existing session: tmux kill-session -t session-idx or tmux kill-session -t session-name.
  • switch attached session: tmux switch -t session-idx or tmux switch -t session-name.
  • rename session: tmux rename-session -t session-idx new_session-name or ctrl+b $.

A session could have multiple windows. Following commands or keyboard-shortcut requires you’re in terminal attaching a session.

  • create a new window: tmux new-window or tmux new-window -n <window-name> or ctrl+b c
  • select window: tmux select-window -t <window-idx> or tmux select-window -t <window-name> or ctrl+b <window-idx>
  • rename window: tmux rename-window <new-name> or ctrl+b ,
  • switch window: ctrl+b n for next or ctrl+b p for prev`
  • list window: ctrl+b w

A window could have multiple panes. Following commands or keyboard-shortcut requires you’re in terminal attaching a session.

  • split window to panes horizontally: tmux split-window -h or ctrl+b %.
  • split window to panes vertically: tmux split-window or ctrl+b ".
  • select up pane: tmux select-pane -U or ctrl+b <up arrow>.
  • select down pane: tmux select-pane -D or ctrl+b <down arrow>.
  • select left pane: tmux select-pane -L or ctrl+b <left arrow>.
  • select right pane: tmux select-pane -R or ctrl+b <right arrow>.
  • move up current pane: tmux swap-pane -U.
  • move down current pane: tmux swap-pane -D.
  • ajust pane size: `ctrl+b ctrl+.
  • turn on/off fullsize on current pane: ctrl+b z.

Questions

History

  • 2023-02-25: create post to record the most commonly used commands