How To Install Tmux and Use On Ubuntu and CentOS 8

We can install Tmux on ubuntu as well as Linux. We can use the following tmux command in Linux. Let’s see, how to install tmux on Linux.

Use the Following Options for Tmux:

Ctrl+b c Create a new window (with shell)
Ctrl+b w Choose window from a list
Ctrl+b 0 Switch to window 0 (by number)
Ctrl+b , Rename the current window
Ctrl+b % Split the current pane horizontally into two panes
Ctrl+b " Split the 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

How To Install Tmux On Ubuntu and CentOS 8

We can install Tmux in a single command on Linux. you may install the Epel-repository if you don’t found the package. 

Check Out: How To Install WordPress 5.5 On Ubuntu 20.04 Server

Installing Tmux on CentOS:

yum install tmux -y

ubuntu tmux install

Installing Tmux on Ubuntu:

sudo apt install tmux

You can also install the Tmux on Mac OS using the below command.

brew install tmux

The Tmux is installed now. we can start using it. 

How To Use Tmux:

You can simply type “tmux” in the Linux shell and it will open new windows in that shell. Once you have opened it, you will see a status line at the bottom of this shell. 

Break a single-window into two Linux terminal as shown below. Use a command “ctrl+b” then “%“. 

tmux command on linux

Check Out: How To Configure Static IP Address On Ubuntu and CentOS 8

If you need to switch the terminal or pane, use this command “ctrl+b” then “left arrow or right arrow“. 

install tmux ubuntu

You can see in the below figure. we’re using the two-terminal in the same windows and checking the top and ls command. you can use the above command.

tmux command

If you want to split another terminal within the same windows, use the “ctrl+b” then command. you can use the same command to break into many. Use the “exit” command to leave that terminal. 

how to install tmux

When you need to open a new window, you can use “ctrl+b” then “c” command. you will notice at the bottom that “[0] 0:bash- 1:bash*”  This output means you have opened the two bash windows.  I will select the windows 0 bash, you will notice a “*” sign at the bottom just after the bash.

I’ll jump on the other windows, use the command “ctrl+b” then “1” command. you just have to select those numbers to switch the windows. 

Check Out: How To Set User Password Policy On CentOS / Redhat 7

We can also rename the window instead of showing the default bash at the bottom. use the command “ctrl+b” then “,“. 

Type any name instead of bash. I have written “tmux” then hit “Enter“. you can see the terminal is renamed as “tmux“. 

In a similar way, if you want to rename the window “0 bash“, you can simply use “ctrl+b” then “0” and again press “ctrl+b” then “,“.

If you want to detach the terminal, use the command “ctrl+b” then “d“. 

[root@local ~]# tmux
[detached (from session 0)]

Use the tmux ls command to check the windows running in the background. only one window opened in the background. 

[root@local ~]# tmux ls
0: 1 windows (created Tue Aug 18 10:27:41 2020) [86x4]

Check Out: How To Integrate Jenkins With S3 Storage To Send The Build

When you need to attach the running session in the background, use the below command. “0” is the session id. 

tmux attach -t 0

Rename session using the command line. 

tmux rename-session -t 0 cent
[root@local ~]# tmux ls
0: 1 windows (created Tue Aug 18 11:20:25 2020) [86x8]
[root@local ~]# tmux rename-session -t 0 cent
[root@local ~]# tmux ls
cent: 1 windows (created Tue Aug 18 11:20:25 2020) [86x8]

Suppose, you want to connect the new session in the same windows. Use the following commands. I had a running session with the name of “top“. you can see, we have now 2 sessions running in the background. 

[root@local ~]# tmux new -s top
[detached (from session top)]
[root@local ~]# tmux ls
cent: 1 windows (created Tue Aug 18 11:20:25 2020) [86x8]
top: 1 windows (created Tue Aug 18 11:25:40 2020) [86x8]

Kill the running session using the following commands. 

[root@local ~]# tmux kill-session -t top
[root@local ~]# tmux kill-session -t cent
[root@local ~]# tmux ls
no server running on /tmp/tmux-0/default

That’s it.

Share on:

I'm the founder of Curious Viral. I hope this blog will provide you complete information about Linux Technology & I would like to share my technical knowledge with you which I have learned during this period.

Other Posts You May Like...

Leave a comment