Terminal Multiplexing with TMux in Linux
Tags: linux, tmux, terminal
Published: 2023-12-03 19:24:10

---
title: Terminal Multiplexing with TMux in Linux
published: true
date: 2023-12-03 19:16:44 UTC
tags: #linux #tmux #terminal
canonical_url: https://itsvinayak.hashnode.dev/terminal-multiplexing-with-tmux-in-linux
---

![Images](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xqwpecmhb2152b08g73x.gif)

As Linux users, most of our time is spent working in the terminal window, and it's no surprise that we often require multiple terminals for multitasking. Thus the invention of multiplexers. Which significantly enhanced the functionality of the terminal, leading to increased productivity.

There are multiple terminal multiplexers but one of the most popular is **TMux.** In this article, we will deep dive into TMux's key features.

**TMux** is a command-line utility for Unix-like operating systems, including Linux. It enables users to create and manage multiple terminal sessions within a single window. In simple words, it's an alternative to using the graphical tabs and lets you organize your terminal into panes and windows.

## Installing TMux in Linux

we can install tmux with our package manager (in the terminal)

- Debian/Ubuntu:
```
  sudo apt-get install tmux
```
- Redhat
```
sudo yum install tmux
```
- Fedora
```
sudo dnf -y install tmux
```

## Starting Tmux inside Terminal

After installing tmux, you can simply start it by typing the command `tmux` in your terminal. This initiates a new tmux session.

```
tmux

```

## **Panes in Tmux**

Similar to Vim, tmux also has a leader key that is used to trigger various commands within tmux., by default its `ctrl + b`

- To split the window vertically, we can use `ctrl + b %`
![window](https://cdn.hashnode.com/res/hashnode/image/upload/v1700499335931/373a0544-c981-4f71-a618-d4d10b7807f9.png?auto=compress,format&format=webp)
- To split the window horizontally, we can use `ctrl + b "`
![window](https://cdn.hashnode.com/res/hashnode/image/upload/v1700499577092/df5bc030-9fb5-4675-a19a-8383b9be7d57.png?auto=compress,format&format=webp)

- Similarly to closing a window, we can use `Ctrl + b x`, and to Navigate between the panes we can use `Ctrl + b <arrow-key>`

- For changing the panel layout leader key with space can be used `Ctrl + b space`

- To resize a panel in tmux, we can use the `resize-pane` command. Press the leader key to enter command mode. Similar to Vim, we can then enter the resize command to adjust the size of the pane using the `:` symbol.
```bash
Ctrl + b : resize-pane -L 10
Ctrl + b : resize-pane -R 10
Ctrl + b : resize-pane -D 10
Ctrl + b : resize-pane -U 10
```

## **Windows in Tmux**

windows in tmux is a little different from Panes, while panes divide the terminal, on the other hand, windows can be used as a new tab. Where each window can contain one or more panes.

- To create a new window, press the leader key and `c` that is `ctrl + b c`

- To Navigate to the next window, `Ctrl + b n` can be used

- To Navigate to the previous window, `ctrl + b p` can be used

- `&` is used to close a window, `ctrl + b &`

### **Renaming windows**

Now that we have multiple windows within our terminal emulator, it's a good idea to rename it to streamline our workflow. For Renaming we can use `,` with `ctrl + b`

![window](https://cdn.hashnode.com/res/hashnode/image/upload/v1700500803944/653bfab6-f7f8-4289-bb0c-c4ef0267fb98.png)

### **List Windows**

We can see a list of windows by using `Ctrl-b` followed by `w`. This provides a visual overview, where we can navigate to a window using the arrow keys.

![window](https://cdn.hashnode.com/res/hashnode/image/upload/v1700501296197/e9ea3649-c2e2-4417-ae0f-4d6278c84439.png)

## Sessions in Tmux

Sessions in Tmux provide an easy way to group tasks or activities in a single terminal multiplexer in one or more instances.

### Creating a Session

As soon as we open tmux in the terminal, a default session is created. However, we can also create a new session with a different name.

For naming a session, we can use the `new-session` command.

```
tmux new-session -s session_name

```

### **Detaching from a Session**

One session is created, and once inside, we can detach it using the combination of `d` after the leader key. `ctrl + b d`

### **Attaching to a Session**

After detaching, we can log back in by attaching it using the `attach-session` command.

```
tmux attach-session -t session_name

```