Linux Commands

How to Navigate Through Panes in tmux

One of the most distinguishing features that differentiate Linux distributions from other operating systems is their fast and versatile command terminal.

The command terminal allows users to enact a complex set of instructions in just a few statements. That being said, there may be times when having a single terminal screen might not be enough for your tasks. However, there are programs that can help you get over this with ease.

tmux: The terminal Multiplexer

tmux, a program created by Nicholas Marriot in 2007, allows you to have more than one session of the command terminal open at a single instance. tmux allows you to create, manage, and navigate through multiple terminal windows at the same time.

One of the most prominent features of tmux is the ability to switch between terminal windows. Knowing how to navigate between different tmux windows and panes can help you manage your commands and shell scripts more efficiently. This guide will help you learn how you can navigate through different panes in tmux.

We’ll go over the basics, starting with the installation and initialization of tmux and proceed with learning the methods of navigating through panes in tmux along with some other useful shortcuts.

Installing tmux on Linux

First and foremost, it is recommended that you ensure that tmux is available on your system. You can verify if tmux is available on your Linux distribution by following these steps:

For this guide, we’ll be using Ubuntu 20.04 LTS. This shouldn’t make a difference as the procedure is similar for all distributions with a slight change in syntax.

First, open the command terminal on your main Linux distribution. The shortcut key is Ctrl + Alt + T.

Once that’s done, type the following command to see if tmux is installed.

$ tmux –version

If the aforementioned command doesn’t return a tmux version as the output, install tmux by typing the following:

For Ubuntu:

$ sudo apt install tmux

For CentOS:

$ sudo yum install tmux

Wait for the installation to complete. Once it’s done, you can move on to the next step.

Starting a tmux Session

The next step is to start a tmux session. This can also be done using the Linux command terminal.

To start tmux, type the following in the terminal:

$ tmux

This should open tmux on your Linux distribution.

Managing and Navigating Through tmux Panes

As mentioned before, tmux is an application that allows its user to run and manage multiple terminal sessions at the same instance. This section will help you learn how you can create and manage your tmux panes and Windows.

tmux makes use of keyboard shortcuts, otherwise known as prefixes. These are combinations of keyboard inputs that are used to categorize different types of functions.

The prefix that’s responsible for pane and Window management is “Ctrl + B”. Almost all commands related to pane management start with this prefix.

Following is a list of commands that can be used to manage tmux panes:

Starting with Ctrl + B and pressing c, this command is used for opening a new tmux window. Furthermore, this window is created with the shell.

The aforementioned command can be used to open multiple Windows. While multiple windows provide a benefit, navigating through them can prove to be a challenge.

To counter this, you can use the following list of commands:

  • Ctrl + B and type w Allows you to select from a list of windows
  • Ctrl + B and type 0 Allows you to switch to window number 0. Replace 0 with any number to move to that window
  • Ctrl + B and type , Allows you to rename a window

These commands are specific to individual windows. Sometimes, you’d wish to have two terminal sessions side by side in the same window. This can be achieved with the help of panes.

There are two methods to split tmux windows into separate panes. One allows you to make horizontal panes whereas the other splits the window into two vertical panes.

To split the tmux window into two vertical panes, press Ctrl + B and type %

To split the tmux window into two horizontal panes, press Ctrl + B and type

You can navigate between the two panes with the help of the following commands:

  • Ctrl + B and type o Allows you to switch to the next pane
  • Ctrl + B and type ; Allows you to alternate between both panes
  • Ctrl + B and type x Allows you to close a pane

Conclusion

Learning how to navigate through tmux panes makes it easier for one to manage their sessions. This was a guide on how you can navigate through panes in tmux. We went over the basics of tmux, the steps to start a new session, and then concluded with how to manage and navigate through tmux panes.

About the author

Zeeman Memon

Hi there! I'm a Software Engineer who loves to write about tech. You can reach out to me on LinkedIn.