Getting Started with Tmux: A Comprehensive Tutorial

Tmux, short for “Terminal Multiplexer,” is a powerful tool that enhances your productivity when working in the command line. It allows you to split your terminal into multiple panes, create and manage multiple terminal sessions, and even detach and reattach sessions, making it an essential tool for developers, system administrators, and anyone who spends a lot of time in the terminal.

In this tutorial, we’ll cover the basics of Tmux, including installation and common commands. By the end of this tutorial, you’ll have a good understanding of how to use Tmux effectively.

Table of Contents

  1. Installing Tmux
  2. Basic Tmux Commands
  3. Working with Panes
  4. Managing Sessions
  5. Customizing Tmux
  6. Additional Resources

1. Installing Tmux

Before you can start using Tmux, you need to install it. The installation process may vary depending on your operating system.

For Linux (Debian/Ubuntu):

sudo apt-get install tmux

For Linux (Red Hat/Fedora):

sudo dnf install tmux

For macOS (using Homebrew):

brew install tmux

For Windows (using Windows Subsystem for Linux):

  1. Install WSL following the official documentation.
  2. Open your Linux distribution in WSL.
  3. Install Tmux using your distribution’s package manager (e.g., sudo apt-get install tmux for Debian-based distributions).

2. Basic Tmux Commands

Once you have Tmux installed, you can start using it with these fundamental commands:

  • Start a new session:

    tmux  
  • Detach from a session:
    Press Ctrl-b followed by d (or simply Ctrl-b and then release, followed by d).

  • List existing sessions:

    tmux list-sessions 
  • Attach to a session:

    tmux attach-session -t session_name 
  • Create a named session:

    tmux new -s session_name  
  • Kill a session:

    tmux kill-session -t session_name 

3. Working with Panes

Tmux allows you to split your terminal into multiple panes for multitasking.

  • Split the current pane horizontally:
    Press Ctrl-b followed by %.

  • Split the current pane vertically:
    Press Ctrl-b followed by ".

  • Switch between panes:

    • To move to the next pane, press Ctrl-b followed by o.
    • To move to a specific pane, press Ctrl-b followed by an arrow key.
  • Close the current pane:
    Press Ctrl-b followed by x.

4. Managing Sessions

Managing sessions is crucial for organizing your work.

Create a new window within a session:
Press Ctrl-b followed by c.

Switch between windows:

To move to the next window, press Ctrl-b followed by n.

To move to the previous window, press Ctrl-b followed by p.

To move to a specific window, press Ctrl-b followed by a number.

Rename the current window:
Press Ctrl-b followed by ,.

5. Customizing Tmux

Tmux can be customized to suit your preferences. You can create a ~/.tmux.conf file to store your configuration settings. Here’s a simple example:

# ~/.tmux.conf
# Customize the prefix key to Ctrl-a
set -g prefix C-a
unbind C-b

# Enable mouse support
set -g mouse on

After creating or modifying your ~/.tmux.conf, reload Tmux with tmux source-file ~/.tmux.conf to apply the changes.

Getting Started with Tmux

Additional Resources

To deepen your knowledge of Tmux, consider exploring these additional resources:

Congratulations! You now have a solid foundation for using Tmux to enhance your command-line productivity. As you become more familiar with Tmux, you can explore its advanced features and further customize it to streamline your workflow. Happy coding!