How to Install and Use Tmux

Last Updated: Mon, Aug 9, 2021
Best Practices FAQ Linux Guides

Introduction

Tmux is a terminal multiplexer. It allows you to run and manage several command prompts simultaneously from one tmux session.

Tmux uses a client/server model, which allows it to persist connections. You can start a session from one computer, run several programs running in it, and then disconnect. You can later reconnect to the same session from a different computer and the same programs will be running.

Install tmux on Debian and Ubuntu

On Debian and Ubuntu systems, install tmux with apt.

$ sudo apt-get update && sudo apt-get -y install tmux

Install tmux on Redhat, CentOS, and Other RHEL-Based Distributions

On Redhat, CentOS, and other RHEL-based systems, install tmux with yum.

$ sudo yum install update && sudo yum -y install tmux

Terminology

  • Pane - A pane is simply a terminal prompt.
  • Window - A window holds multiple panes (terminals) on one screen.
  • Session - A session has multiple windows.

Start a New tmux Session

$ tmux new -s start

You will see a bar at the bottom of the screen with the session name tmux created, start, in brackets. This is because Tmux automatically logs in with your user account when it creates new panes.

Maneuvering in tmux

Once inside a tmux session, you use a prefix key to trigger commands to tell tmux what to do. The default prefix key is CTRL + B. For example, if you want to tell tmux to create a new pane by splitting your screen into two vertical sections, you first type CTRL + B, then %.

Create Multiple Panes

If you typed CTRL + B, then % as shown above, then you have two panes on your screen.

  1. Split the current pane into two horizontal sections by typing CTRL + B, then ".
    • To cycle through all three panes, type CTRL + B, then O.

Create Multiple Windows

  1. Create a new window in the start session. Type CTRL + B, then C to open a new blank terminal.
  2. Split this terminal into two horizontal panes with CTRL + B, then ".
  3. Create a third window with CTRL + B, then C.

    You will see a new blank terminal again.

  4. Issue the command tmux list-windows, then press ENTER to confirm that you have three windows opened.

  5. Use CTRL + B, then N to cycle between the three windows created.

Attach and Detach to/from a Session

  • Use CTRL + B, then D to detach from your current session.
  • Reconnect to your session with tmux attach -t YOUR_SESSION_NAME.
  • Use CTRL + B, then N to cycle between the windows in your session.

Common Key Bindings

  • CTRL + B, then C : Create new window.
  • CTRL + B, then , : Rename a window.
  • CTRL + B, then N : Move to the next window.
  • CTRL + B, then P : Move to the previous window.
  • CTRL + B, then & : Kill current window.
  • CTRL + B, then % : Split current pane into two (vertically).
  • CTRL + B, then " : Split current pane into two (horizontally).
  • CTRL + B, then O : Switch to next pane.
  • CTRL + B, then Q : Show pane numbers (then type a # to switch to it).
  • CTRL + B, then D : Detach from current session.
  • CTRL + B, then ? : List all key bindings.

Common Commands

  • tmux list-sessions - List existing tmux sessions.
  • tmux new -s session-name - Create a new tmux session named session-name.
  • tmux attach -t session-name - Connect to an existing tmux session named session-name.
  • tmux switch -t session-name - Switches to an existing tmux session named session-name.

More Information

Want to contribute?

You could earn up to $600 by adding new articles