How to Use tmux on Linux?

The Tmux is the multiplexer terminal tool that allows users to work on multiple terminal windows at the same time. The Tmux is helpful when users are supposed to perform multiple tasks and monitor them simultaneously. 

In this blog, the detailed usage of the Tmux on Linux has been explained with the help of some examples:

Prerequisite: Installation of Tmux on Linux

The Tmux can be installed on Linux distributions by using the commands mentioned below:

$ sudo apt install tmux -y       #Ubuntu/Debian
$ sudo dnf install tmux           #Fedora
$ sudo yum install tmux         #RHEL-based

After ensuring the installation of the Tmux, we will proceed to the next section.

How to Use the Tmux on Linux?

Different usages of the Tmux are explained with examples in the next section. First, we will launch the Tmux using the command:

$ tmux

When the tmux is opened; then users can find the below-mentioned screen:

To apply different shortcut keys, first, we should press the prefix key to enter the command mode, which can be done by pressing the “CTRL+b”:

Now, we will explain different usages of the Tmux with examples. 

Example 1: Split the Terminal Screen Horizontal 

To split the screen horizontally, we will use the prefix key with the single double quotes “ , which is explained:

The pane is split horizontally. 

Example 2: Close the Active Pane

To close or kill the active pane, we can use the “x” option with the Prefix key:

Press the “Y” to confirm the operation:

The pane has been closed. 

Example 3: Split the Terminal Screen Vertically

To split the pane vertically, we will use the prefix key with the percentage %, which is explained:

The pane is divided vertically. 

Example 4: Rename the Current Session

To rename the current session, we can use the “$” with the prefix key:

Type the new name of the session and press the “ENTER” key. For example, we have set the name “MADDOX”:

The name has been set to MADDOX successfully.

Example 5: Display the Pane Numbers

To display the current pane number, press the “i” with the prefix key:

We are working on pane number 1 which is displayed at the bottom of the figure. 

Example 6: Adjust the Tmux Pane Size

To change the pane size of the Tmux with the custom dimensions, a resize-pan command is explained in the blog:

The current pane’s size has been increased. 

Example 7: Attach the Tmux Session

To attach another Tmux session, run the command following the mentioned-below general syntax:

$ tmux attach-session -t [session name]

To get more information about attaching the Tmux session on Tmux, read the article

Example 8: Detach the Tmux Session

The users can detach the sessions they are not using by following the general syntax mentioned below:

$ tmux detach -s [session name]

For more information on detaching the Tmux session, visit the link

Example 9: Kill All Tmux Sessions

To kill or close all the active sessions of the Tmux, execute the command:

$ pkill -f tmux

To learn more methods of killing all the Tmux sessions, visit the following link

Example 10: Display All the Options of the Tmux Command

To display all the options of the Tmux with their description, use the “question mark ?” with the prefix command:

The options of the Tmux have been displayed.

Conclusion

To use the Tmux on Linux, use different options with the prefix key that is CTRL+b. All the options can be displayed with the shortcut “Prefix key+?”. This post has explained the installation and detailed working of the tmux in Linux.