How to Install And Use Tmux in Linux with Example

Learn How to Install And Use Tmux in Linux

In this post, we are going to show that how to Install And Use Tmux in Linux. If your are going to Install and use Tmux on your Linux system then this post is ideal for you.

Tmux is an open-source and popular terminal multiplexer for Unix-like operating systems. Tmux allows you to start a Tmux session and then open multiple windows within that session. It is an alternative to GNU Screen. It is very useful when you are running multiple command-line program at the same time.


How to Install and Use Tmux on Linux

Simply follow below steps to install and use Tmux on your Linux system:

Install Tmux on Ubuntu and Debian

sudo apt install tmux

Installing Tmux on CentOS and Fedora

sudo yum install tmux

Install Tmux on macOS

brew install tmux

Start Tmux Session

Now, Tmux is installed and ready to use. To start your first Tmux session, type and run  tmux in your terminal:

tmux

The above command create a new session with a new window and start a shell within that window. In this window, you can run tmux commands. For an example, if you want to get a list of all commands, type Ctrl+b ?

termux-1

Create Tmux Session with Name

By default, When you create a tmux session, it is named numerically. If you want to create a new session with name, run the tmux command as show below:

tmux new -s session_name
termux 2

Replace session_name with your desired name.


Detach from Tmux Session 

If you want to detach from the Tmux session and want to return to main shell, type Ctrl+b d .

It show a message similar like below:

[detached (from session 7)]

Re-attach to Tmux Session 

If you want to re-attach a tmux session, first you will need to find the name of the tmux session using command below:

tmux ls
Output
0: 1 windows (created Mon May 10 16:08:28 2021)
7: 1 windows (created Mon May 10 18:05:30 2021)
session_name: 1 windows (created Mon May 10 16:09:23 2021)
studiesonline: 1 windows (created Mon May 10 17:45:24 2021)

The first column of the output is name of the session.

To re-attach to session studiesonline, run the command below:

tmux attach-session -t studiesonline

Tmux Windows and Panes Management

Here, we are show some most common and useful commands for managing Tmux windows and panes:

  • Ctrl+b c – It is create a new window (with shell)
  • Ctrl+b w – It is used to choose window from a list
  • Ctrl-b [0-9] – Switch between windows (by number )
  • Ctrl+b , –  It is used to rename the current window
  • Ctrl+b %  – Split current pane horizontally into two panes
  • Ctrl+b " – It is used to split current pane vertically into two panes
  • Ctrl+b o – Go to the next pane
  • Ctrl+b ; – Toggle between the current and previous pane
  • Ctrl+b x – Close the current pane

Examples:

Use the below key combination to rename an active session:

Ctrl-b $

After run the command, provide new session name and press enter key.

Use the below key combination to switch session:

Ctrl-b s

If you want to create a new window, use the below key combination:

Ctrl-b c

To destroy tmux window, use the below key combination:

Ctrl-b x

To switch between windows, use the below key combination:

Ctrl-b [0-9]
Ctrl-b 0

Use the below key combination to split windows horizontally:

Ctrl-b %

To Split windows vertically, use the below key combination

Ctrl-b "

That’s all

If you face any error and issue in above steps , please use comment box below to report.

If our tutorials helped you, please consider buying us a coffee. We appreciate your support!

Thank you for your support.

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top