Tmux: The Terminal with Superpowers

📝 Introduction

Have you ever wondered how to dramatically increase your productivity in the terminal? Today I’m going to introduce my favorite tool in the development and security universe: Tmux.

Tmux can be defined as a “terminal on steroids” or, more technically, as a terminal multiplexer. When you learn to use it effectively, your terminal tasks become significantly more agile, flexible, and organized. Imagine being able to work on multiple servers, execute various commands, and monitor different processes—all within a single terminal window!

⚙️ Understanding the Basic Functionality of Tmux

Tmux operates based on a fundamental concept: a command prefix followed by an action key. This two-step structure allows Tmux to offer dozens of features without conflicting with existing terminal shortcuts.

The default prefix is Ctrl + B, although it’s possible (and common) to customize it as we’ll show later. This interaction pattern is essential for understanding the tool:

  1. Press Ctrl + B
  2. Release the keys
  3. Press the key corresponding to the desired command

It’s important to remember that this two-step flow must be followed for all the commands we’ll explore next.

🚀 Starting Your Journey with Tmux

To begin using Tmux, you’ll need to open your standard terminal and start a session. There are two main approaches:

# Starting Tmux with the basic command
tmux

# Starting a named session (recommended)
tmux new -s SESSION_NAME

The second option is particularly useful as it creates a session with a specific name of your choosing. This name greatly facilitates finding and reconnecting to the same session later, especially if you work on multiple projects or need to recover your environment after a disconnection.

🗂️ Working with Panes and Windows

When Tmux is running, you’ll notice a subtle change in the interface—mainly a status bar at the bottom of the window. This bar displays information about your current panes, which function like terminal tabs.

Managing Windows

To create a new window (technically called a “window” in Tmux):

  1. Press Ctrl + B
  2. Press c (for “create”)

You’ll notice that the bottom bar now shows a new window, indicated with an asterisk (*) to mark which one is currently active.

To navigate between different windows:

  1. Press Ctrl + B
  2. Press the number of the desired window (starting from 0 for the first window)

Splitting Your Screen into Multiple Panes

One of the most powerful features of Tmux is the ability to split your screen into multiple panes, allowing you to view different terminals simultaneously:

  • For a horizontal split (one terminal above another):
    1. Press Ctrl + B
    2. Press (double quotes)
  • For a vertical split (terminals side by side):
    1. Press Ctrl + B
    2. Press % (percent)

To navigate between different panes after creating them:

  1. Press Ctrl + B
  2. Use the arrow keys (↑ ↓ ← →) to move in the desired direction

A particularly useful feature is zoom mode, which allows you to temporarily expand a pane to occupy the entire screen:

  1. Press Ctrl + B
  2. Press z (zoom)

To return to the split view, simply repeat the same command (Ctrl+B, z).

📜 Navigation and Text Scrolling

In the standard terminal, you typically use the mouse wheel to scroll text up and down. In Tmux, navigation works slightly differently:

  1. Press Ctrl + B
  2. Press ] (closing bracket)

This activates navigation mode, indicated by an orange marking in the upper right corner of the screen. In this mode, you can:

  • Use the arrow keys to move through the text
  • Use Page Up and Page Down to scroll entire pages

This navigation system, although initially different from what you’re used to, offers much more precise control over viewing extensive logs or command outputs.

📋 Copy and Paste in Tmux: The Smart Clipboard

Tmux implements its own clipboard system, independent of the operating system. This enables an extremely useful functionality: the ability to maintain two distinct clipboards simultaneously—one from the system and another internal to Tmux.

To copy text using the Tmux clipboard:

  1. Enter edit mode:
    • Press Ctrl + B
    • Press [ (opening bracket)
  2. Start text selection:
    • Navigate to the beginning of the desired text
    • Press Space to begin selection
  3. Select the text:
    • Use the arrow keys to expand the selection (the text will be highlighted in orange)
    • Press Enter to copy the selection to the Tmux clipboard
  4. Paste the text:
    • Press Ctrl + B
    • Press ] (closing bracket)

This functionality is particularly valuable when you need to keep different code snippets or commands available for quick use in different contexts.

🛠️ Additional Commands and Advanced Features

Tmux has a vast set of commands beyond those mentioned, including functions to rearrange panes, join sessions, rename windows, and much more. The complete list would be extensive to cover here, but excellent resources are available:

⚙️ Customizing Tmux: Advanced Configuration

One of the biggest advantages of Tmux is its high customizability. You can completely adapt its behavior by editing the configuration file:

vi ~/.tmux.conf

Below is an example configuration inspired by Ippsec’s settings (a respected security professional), which we can examine line by line:

# Change the default prefix from Ctrl+B to Ctrl+A (more ergonomic)
set -g prefix C-a
bind C-a send-prefix
unbind C-b

# Increase history limit to 10,000 lines
set -g history-limit 10000

# Prevent automatic window renaming
set -g allow-rename off

# Shortcuts for joining panes (j) and sending panes (s)
bind-key j command-prompt -p "join pane from:" "join-pane -s '%%'"
bind-key s command-prompt -p "send pane to:" "join-pane -t '%%'"

# Configure navigation mode to use VI/VIM style keys
set-window-option -g mode-keys vi

# Configure the logging plugin for session saving
run-shell /opt/tmux-logging/logging.tmux

This configuration demonstrates some common modifications that make Tmux even more powerful:

  1. Changing the prefix to Ctrl+A, easier to reach on the keyboard
  2. Increasing the history buffer to retain more information
  3. Disabling automatic renaming to maintain your own tab descriptions
  4. Adding custom shortcuts for pane manipulation
  5. Configuring navigation mode to use VI/VIM style controls
  6. Integrating with the logging plugin to save session records

🔄 Connecting to Existing Sessions

One of the most powerful features of Tmux, especially for those working with remote servers, is the ability to disconnect and reconnect to ongoing sessions. This means you can start a long process, disconnect, and return later to check the progress—everything exactly as you left it.

To list available sessions:

tmux ls

To reconnect to an existing session:

tmux attach -t SESSION_NAME

To disconnect from a session without ending it:

  1. Press Ctrl + B
  2. Press d (detach)

🎓 Conclusion and Next Steps

Tmux is an exceptionally powerful tool that, while requiring some time to fully master, offers incomparable returns in terms of productivity and efficiency. The commands might seem complex initially, but with practice, they become natural reflexes that will permanently transform your interaction with the terminal.

I recommend starting with the basic commands—creating windows, splitting panes, and navigating between them—before advancing to more complex features. As you become familiar with these fundamentals, you’ll naturally discover which additional functionalities are most relevant to your specific workflow.

Bear hugs and see you in the next post!


🌐 Additional Resources:

  • Discord: Join our community for discussions and tips!
  • Ippsec’s Channel (in English): https://www.youtube.com/c/ippsec – An excellent resource for learning more about terminal tools and security.