Skip to main content

Introduction to tmux Terminal Multiplexer

Tmux (terminal multiplexer) is a powerful terminal multiplexer that allows users to access multiple independent sessions within a single terminal window, as well as detach from and reattach to sessions. With tmux, you can disconnect from a session without interrupting running processes and reconnect later. Here is a basic guide on using tmux on Unix-like systems:

  1. Install tmux: On most Unix-like operating systems, you can install tmux using the package manager. For example, on Debian or Ubuntu:

    sudo apt update
    sudo apt install tmux
  2. Start tmux: Enter the tmux command to start a tmux session:

    tmux

    If you want to start a session with a specific name:

    tmux new -s my_session

    This makes it easier to remember and manage your sessions.

  3. tmux session control

    • tmux ls: List all current tmux sessions.
    • tmux attach -t my_session: Reattach to the session named my_session.
    • tmux kill-session -t my_session: Kill the session named my_session.
  4. Split panes

    • Ctrl+b ": Split the current pane horizontally.
    • Ctrl+b %: Split the current pane vertically.
  5. Switch panes

    • Ctrl+b arrow keys: Use the arrow keys to switch between panes.
    • Ctrl+b o: Cycle to the next pane.
  6. Resize panes

    • Ctrl+b then arrow keys: Hold Ctrl+b and press the arrow keys to resize the pane.
  7. Window (tab-like) management

    • Ctrl+b c: Create a new window.
    • Ctrl+b p: Switch to the previous window.
    • Ctrl+b n: Switch to the next window.
    • Ctrl+b number: Switch to the window with the specified number, where number is the zero-based window index.
  8. Detach from a session

    • Ctrl+b d: Detach from the current session. This allows you to close the terminal without ending the tmux session.
  9. Customize tmux You can customize tmux by editing the ~/.tmux.conf configuration file.

  10. Exit tmux

    • Without split panes, simply type exit or press Ctrl+d to exit.
    • If there are multiple panes, you need to exit from each pane individually.

The above covers some basic tmux usage. tmux is very powerful and includes, but is not limited to, session management, window and pane management, custom keybindings, scripting, and automation. It is recommended to read the manual (man tmux) or a more detailed tutorial to fully understand all its features.