DEV Community

vinayak
vinayak

Posted on • Originally published at itsvinayak.hashnode.dev on

Terminal Multiplexing with TMux in Linux

Images

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
Enter fullscreen mode Exit fullscreen mode
  • Redhat
sudo yum install tmux
Enter fullscreen mode Exit fullscreen mode
  • Fedora
sudo dnf -y install tmux
Enter fullscreen mode Exit fullscreen mode

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

Enter fullscreen mode Exit fullscreen mode

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
  • To split the window horizontally, we can use ctrl + b "
    window

  • 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.

Ctrl + b : resize-pane -L 10
Ctrl + b : resize-pane -R 10
Ctrl + b : resize-pane -D 10
Ctrl + b : resize-pane -U 10
Enter fullscreen mode Exit fullscreen mode

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

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

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

Enter fullscreen mode Exit fullscreen mode

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

Enter fullscreen mode Exit fullscreen mode

Top comments (1)

Collapse
 
theresapowell profile image
TheresaPowell

TMux is a game-changer for terminal multiplexing in Linux. Lotus book 247 sign up