Open In App

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

Last Updated : 29 Jan, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

tmux, or Terminal Multiplexer is a command-line tool for managing multiple terminal sessions in one window. It’s beneficial for developers and system administrators, offering features like splitting the terminal into panes, creating sessions with windows and panes, customization, scripting, and remote access. Users can organize tasks efficiently, customize their environment, and automate repetitive tasks. tmux is particularly useful for remote work, allowing detachment and reattachment to sessions. It’s initiated by typing ‘tmux’ in a terminal, with commands for creating panes, and windows, and customizing the environment.

One of its important features is the ability to split the terminal into panes, allowing users to handle multiple tasks at the same time within the same window. This article provides a step-by-step guide on opening and managing multiple panes in tmux.

Why do we need multiple tmux Panes?

Many terminal users find it challenging to easily manage multiple tasks concurrently. For example, suppose you are running tests for your application and also need to keep an eye on system resources. Tmux simplifies this by splitting the panes. Now you can run tests in one pane while monitoring system resources in the other.

Another example: Let’s say you are working on a web development project, and you need to run various commands to manage your project, such as running a version control system like Git managing dependencies with npm, and monitoring server logs. tmux panes can be valuable in this situation. You can have one pane for running Git commands or managing dependencies with npm and another for monitoring server logs. This way, you can easily switch between these tasks without needing to open multiple terminal windows or tabs.

tmux-panes

tmux Panes.

Opening and working with multiple panes at the same time in tmux.

Method 1: For splitting the current pane vertically, use `Ctrl+b` followed by `%`. To split horizontally, press `Ctrl+b` and `“`.

Step 1: Open the terminal and, if not already installed, install tmux using the following command:

sudo apt install tmux

Installing tmux.

Installing tmux

Step 2: Open the terminal. Connect to a remote computer if you are using one. Launch tmux with `tmux` command.

tmux

running tmux

running tmux

Step 3: Vertical Split

For a vertical split, press `% ` after `Ctrl+b.` This action will split the current pane into two vertical panes, effectively dividing the terminal window.

vertical-split-of-tmux-pane

Vertilcal split of tmux pane.

Step 4: Horizontal Split

To split the pane horizontally, press `“` after `Ctrl+b` . This will create two horizontal panes within the terminal window.

Horizontal-splitting-tmux-panes

Horizontal split of tmux pane.

We can also split the already divided panes further by navigating through the split panes and using the same command for splitting.

Method 2: Another method for splitting the screen vertically within tmux is to use the command `tmux split-window -v`. To split the screen horizontally, execute the command `tmux split-window -h` within a tmux session. Let’s understand this with following image representation:

splitting-panes

splitting panes using `tmux split-window`

Method 1: To navigate through split panes in tmux, press `Ctrl+b`and then use the arrow keys to move between panes within the current window.

navigating-in-tmux-panes

Navigating split panes in tmux.

Method 2: To navigate through split panes in tmux, press `Ctrl+b`, and then press `o` to toggle between the split panes.

Method 3: Press `q` after pressing `Ctrl+b`, and you will see the index of all the split panes. To switch to a particular pane, press the respective index, and you will be directed to that specific pane.

using-ctrl-b-and-q-in-tmux

using `ctrl+b` and `q` in tmux

In the image, you can see that after pressing `q` following `Ctrl+b`, the index of all panes is displayed in every pane. To switch to a specific pane, press the corresponding index.

Closing the split panes in tmux

Method 1: To close a specific split pane in tmux, simply type the command `exit`, and the pane will be closed.

closing-tmux-panes

Closing the split panes in tmux.

Method 2: Another method for closing panes in tmux is to press “x” after pressing Ctrl + b. This action will close the current active pane.

Closing the tmux session

Method 1: To close a tmux session, the exit command is used.

closing-the-tmux-session

Closing the tmux session using ‘exit’ command

Conclusion

The step-by-step guide outlined here gives a brief overview of how to open, navigate, and close panes in tmux. This tool is essential for handling multiple tasks simultaneously, simplifying complex activities without requiring extra terminal windows. Learning tmux shortcuts can greatly enhance user productivity, making it a valuable addition to the command-line toolkit.



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads