tmux 101

vigneshm
2 min readJul 17, 2024

--

tmux is a terminal multiplexer. We can have multiple terminals inside a single terminal, which is especially useful when we ssh into a remote machine.

tmux has 3 levels of hierarchy,

  • Sessions — To have completely different work environments for different concerns
  • Windows — To have multiple tabs for what that window represents, basically one for monitoring logs and performance and another to execute the commands required.
  • Panes — To have different panes inside a window, like one running top, and another running a couple of tail commands on log files.

To start using tmux, we just need to run the command tmux.

One key concept in tmux is the concept of prefix key. After pressing the prefix key, tmux enters command mode, similar to vim’s insert, command, and view modes. The prefix key for tmux by default is Ctrl + B.

Basic commands

  • Start a new session
tmux
  • Detach from a session
Ctrl+B d
  • Attach to the last accessed session
tmux attach
  • Exit and quit tmux
Ctrl+B &

Session management

  • Create a named session
tmux new -s <session_name>
  • Attach to a session
tmux attach -t <session_name>

or

tmux a -t <session_name>
  • Switch sessions
tmux switch -t <session_name>
  • List sessions
tmux ls
  • Kill sessions
tmux kill-session -t <session_name>

Window management

KeyOperationCtrl+B CCreate new windowCtrl+B NMove to next windowCtrl+B PMove to previous windowCtrl+B LMove to last windowCtrl+B 0–9Move to window by index number

Pane management

KeyOperationCtrl+B %Vertical split (panes side by side)Ctrl+B “Horizontal split (one pane below the other)Ctrl+B OMove to other paneCtrl+B !Remove all panes but the current one from the windowCtrl+B QDisplay window index numbersCtrl+B Ctrl-Up/DownResize current pane (due north/south)Ctrl+B Ctrl-Left/RightResize current pane (due west/east)Ctrl+B WOpen a panel to navigate across windows in multiple sessions

Command mode

Some other key points are we can enter command mode by

Ctrl + B :

We can allow access to a mouse by

set -g mouse

Tmux config

We have a tmux config file that is a dot config file. We can create it using the following command.

vi $HOME/.tmux.conf

We can add the above command to allow mouse usage into the tmux conf file.

Tmux References

There is a lot more to tmux than this, which we can check out from the tmux manual.

Originally posted on vignesh.page.

Hope tmux improves your daily workflow as it did mine. Comment out any cool features or tmux plugins that you find useful.

--

--

vigneshm
vigneshm

No responses yet