Tmux: An Introduction to Terminal Multiplexing

Boost your productivity with Tmux and take control of your terminal workflow

Introduction

Tmux (Terminal Multiplexer) is a powerful tool that allows you to split a single terminal window into multiple panes, run multiple sessions within a single terminal, and detach and reattach to sessions later across different terminals or even a different computer. This can be extremely useful if you need to work remotely or switch between different devices or simply protect your process because the process will not be terminated when the terminal is closed or the connection is lost.

Key features

Here’s a brief overview of some of the key features of tmux:

  • Sessions: a Tmux session is a collection of one or more windows, each containing one or more panes. You can create, rename, and switch between sessions using various Tmux commands.
  • Windows: a tmux window is a full-screen pane that can be split into multiple panes. You can create, rename, and switch between windows within a session.
  • Panes: a tmux pane is a sub-division of a window that allows you to view and interact with multiple terminals at once. You can split and resize panes vertically and horizontally, and switch between them using various tmux commands.
  • Detaching and reattaching: one of the most powerful features of tmux is its ability to detach and reattach to sessions. This means that you can start a long-running process (such as a server or a script) in a tmux session, detach from the session, and then reattach to it later from a different terminal or even a different computer.
  • Customization: tmux is highly customizable, with a wide range of configuration options and key bindings that can be modified to suit your needs.

Basic commands

Here are some basic commands to get started with tmux.

Install and launch first tmux session

1
2
3
4
# install tmux:
$ sudo apt-get install tmux
# launch tmux:
$ tmux

In tmux we have Prefix = Ctrl + b (default)

Session

In tmux we can:

  • Create/ Kill a session
    • Create:
      1
      
        $ tmux new -s <session-name>
      
    • Kill
      1
      
        $ tmux kill-session -t <session-name>
      
  • Rename a session:
    • Attach to the session, then rename it by Prefix + $ + <new-session-name>, or
      1
      
        $ tmux rename-session -t <old-session-name> <new-session-name>
      
  • Attach to a session:
    1
    
      $ tmux attach -t <name-session>
    
  • List all session:window:
    1
    2
    3
    
      $ tmux ls
      # 0: 2 windows (created Tue Apr 25 08:52:02 2023) [80x23] (attached)
      # 1: 1 windows (created Tue Apr 25 08:57:50 2023) [80x23] (attached)
    

Window

Inside a session we can:

  • Create/ Kill a window:
    • Create: Prefix + c
    • Kill: Prefix + &, or:
      1
      
        $ tmux kill-window -t <window-number>
      
  • Switch windows: Prefix + <window-number>
    1
    2
    
      # <window-number>: <window-name>
      [2] 0:bash* 1:bash  2:bash-
    
  • Rename a window: switch to the window Prefix + <window-number>, then rename it by
    • Prefix + , + <new-window-name>, or
      1
      
        $ tmux rename-window <new-window-name>
      
  • Exit a window: exit
  • Detach: Prefix + d

Pane

Inside a window we can:

  • Create a new pane:
    • horizontally: Prefix + %
    • vertically: Prefix + "
  • Kill a pane: Prefix + x
  • Switch panes: Prefix + o
  • Move a pane: Prefix + Ctrl + o

References

  1. https://github.com/tmux/tmux/wiki
  2. https://arcolinux.com/everthing-you-need-to-know-about-tmux-panes/