DEV Community

Cover image for TMUX the terminal multiplexer
Ernesto Herrera Salinas
Ernesto Herrera Salinas

Posted on

TMUX the terminal multiplexer

TMUX, short for terminal multiplexer, is a powerful command-line tool used to manage multiple terminal sessions within a single window. It's widely used by developers, system administrators, and power users for its ability to keep applications running in the background, to switch between several programs in one terminal, and to detach and reattach sessions from a terminal. This article will guide you through some of the most commonly used features of TMUX, providing step-by-step examples for each.

1. Starting a New Session

To begin using TMUX, you need to start a new session. This can be done by simply typing tmux in your terminal. However, it's often helpful to name your sessions for easy identification.

Example:

tmux new -s my_session
Enter fullscreen mode Exit fullscreen mode

This command starts a new TMUX session named my_session.

2. Detaching and Reattaching Sessions

One of the key features of TMUX is the ability to detach from a session and leave it running in the background, then reattach to it later.

Detaching:

  • To detach from a session, press Ctrl+b then d.

Reattaching:

  • To reattach to a session, use:
  tmux attach -t my_session
Enter fullscreen mode Exit fullscreen mode

3. Managing Windows and Panes

TMUX allows you to have multiple windows within a session, and each window can be split into multiple panes.

Creating a New Window:

  • Press Ctrl+b then c. This creates a new window.

Splitting Windows into Panes:

  • Horizontal split: Press Ctrl+b then %.
  • Vertical split: Press Ctrl+b then ".

Switching Between Panes:

  • Use Ctrl+b arrow keys (up, down, left, right).

4. Customizing the Environment

TMUX is highly customizable. You can modify the appearance and behavior by editing the .tmux.conf file in your home directory.

Example:

  • To change the prefix key to Ctrl+a, add this to .tmux.conf:
  unbind C-b
  set-option -g prefix C-a
  bind-key C-a send-prefix
Enter fullscreen mode Exit fullscreen mode

5. Session Management

TMUX sessions are persistent, which means you can list all sessions and switch between them.

Listing Sessions:

  • Use tmux ls to list all active sessions.

Switching Sessions:

  • Use tmux switch -t session_name to switch to a different session.

Conclusion

TMUX is a versatile tool that greatly enhances productivity in a terminal environment. These basic commands and examples provide a foundation for exploring its more advanced features and customizations. Whether you're a beginner or an experienced user, TMUX can be tailored to suit your workflow and preferences, making it an indispensable tool for many.

Top comments (0)