Terminal Multiplexing with TMux in Linux

Terminal Multiplexing with TMux in Linux

ยท

3 min read

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 us organize our 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 our 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 %

  • To split the window horizontally, we can use ctrl + b "

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

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

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.

Sessions in Tmux

Sessions in Tmux provide an easy way to group tasks or activities together 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

Did you find this article valuable?

Support Vinayak Sharma by becoming a sponsor. Any amount is appreciated!

ย