How to Use ‘Tmux Terminal’ to Access Multiple Terminals Inside a Single Console

System administrators often need to work on multiple consoles and thus they appreciate the ability to switch from one to another in a snap with a quick keyboard shortcut or mouse click.

Tmux Manage Multiple Linux Terminals Inside Single Console
Tmux Manage Multiple Linux Terminals Inside Single Console

To do this, in GNOME-based desktop Linux distributions you can install a tool called Terminator, which provides an efficient way of splitting a single window into multiple terminals for different tasks.

Terminator – Manager Multiple Terminal Windows for Multiple Linux Tasks

However, there are other options that you will need to consider, specially if you’re in front of a CLI-only server or if the X Windows System has crashed in your desktop distribution. Additionally, certification programs such as the Linux Foundation Certified System administrator, the Linux Foundation Certified Engineer only provide a command line interface for their respective exams.

In this article we will introduce you to tmux (short for Terminal MUltipleXer), a simple and modern alternative to the well-known GNU screen utility, and will enable you to access and control a number of terminals (or windows) from a single terminal. This tool will work both in a CLI-only environment and within a terminal emulator in a desktop distribution.

In addition, being able to create multiple tmux sessions can help you organize your work into different areas to increase your productivity.

Update: Here is another article about wemux, that improves tmux to make multi-user terminal easier and more powerful. It enables users to start a new wemux server and have other users join in either, read more about it:

Setup Wemux with Tmux/Terminator to Allow Remote Viewing of Your Linux Terminal

Installing tmux Terminal Multiplexer in Linux

To install tmux, you can use your standard package management system.

For CentOS/RHEL/Fedora (included in the base repository):

# yum update && yum install tmux

Debian (from the admin packages section of the stable version) and derivatives:

# aptitude update && aptitude install tmux

Once you have installed tmux, let’s take a look at what it has to offer.

Getting Started with tmux Terminal Multiplexer

To start a new tmux session (a container for individual consoles being managed by tmux) named dev, type:

# tmux new -s dev

At the bottom of the screen you will see an indicator of the session you’re currently in:

Tmux Terminal Indicator
Tmux Terminal Indicator

Next, you can:

    1. divide the terminal into as many panes as you want with Ctrl+b+" to split horizontally and Ctrl+b+% to split vertically. Each pane will represent a separate console.
    2. move from one to another with Ctrl+b+left, +up, +right, or +down keyboard arrow, to move in the same direction.
    3. resize a pane, by holding Ctrl+b while you press one of the keyboard arrows in the direction where you want to move the boundaries of the active pane.
    4. show the current time inside the active pane by pressing Ctrl+b+t.
    5. close a pane, by placing the cursor inside the pane that you want to remove and pressing Ctrl+b+x. You will be prompted to confirm this operation.
    6. detach from the current session (thus returning to the regular terminal) by pressing Ctrl+b+d.
    7. create a new session named admin with
# tmux new -s admin
    1. detach from the session named admin
    2. reattach to the session named dev with
# tmux attach -t dev
    1. Switch to admin again with
# tmux switch -t admin

All the examples above are illustrated in the following screencast. Please take a minute to watch it and practice before proceeding:

Note that when there are no more panes left in a tmux session, such session is terminated.

Changing tmux Terminal Key Bindings

In tmux, the combination of keys used to perform a certain action is called key bindings. By default, key bindings consists of a combination of the Ctrl key and other(s) key(s), as we explained in the previous section.

If you find the default key bindings used in the preceding examples inconvenient, you can change it and customize it on either 1) a per-user basis (by creating a file named .tmux.conf inside each user’s home directory – do not omit the leading dot in the filename) or 2) system-wide (through /etc/tmux.conf, not present by default).

If both methods are used, the system-wide configuration is overridden by each user’s preferences.

For example, let’s say you want to use Alt+a instead of Ctrl+b, insert the following contents in one of the files mentioned earlier as needed:

unbind C-b
set -g prefix M-a

After saving changes and restarting tmux, you will be able to use Alt+a+" and Alt+a+t to split the window horizontally and to show the current time inside the active pane, respectively.

The man page of tmux provides additional details and further suggestions for convenient key bindings that I’m sure you’ll find interesting to try.

Summary

In this article we have explained how to use tmux to divide your terminal or console window into multiple panes that you can use for different purposes.

I hope you have found this tool useful (actually, I’d love to hear that!), feel free to drop us a line using the form below. Do the same if you have any comments, questions or suggestions about this article.

Reference: https://tmux.github.io/

Hey TecMint readers,

Exciting news! Every month, our top blog commenters will have the chance to win fantastic rewards, like free Linux eBooks such as RHCE, RHCSA, LFCS, Learn Linux, and Awk, each worth $20!

Learn more about the contest and stand a chance to win by sharing your thoughts below!

Gabriel Cánepa
Gabriel Cánepa is a GNU/Linux sysadmin and web developer from Villa Mercedes, San Luis, Argentina. He works for a worldwide leading consumer product company and takes great pleasure in using FOSS tools to increase productivity in all areas of his daily work.

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.

6 Comments

Leave a Reply
  1. Please help me how to use tmux in putty, as I am using Linux rhel7.

    I have installed tmux with command: yum install tmux and started tmux on the system.

    I have type also ctrl+b % and then :set synchronize-panes but second machine through putty . How ?

    I want first machine typing another machine automatically run the command both machine. Please help me.

    Thanks you.

    Reply
  2. Thanks, I have used x-window in Red Hat Linux 7. Ctrl+Alt+F1/F2/F3/F4/F5/F6 to get multiple console. But this one is good to see in one screen.
    Best regards…

    Reply

Got Something to Say? Join the Discussion...

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.