Tmux is what is called a multiplexer. A multiplexer allows you to run multiple terminal sessions at once. Or run a terminal session in the background. This is useful when you need to access multiple ssh sessions at a time or just for a good general workflow. For example, you can run htop while downloading the latest system update, edit a config file and restart the service all on one tmux session. In this article, we will install tmux and go over some useful commands to get you started.
Let's go ahead and select the icon and search for the terminal in the search and then click on the terminal to open.
Next, let's update our system packages and install tmux
sudo apt update
sudo apt install tmux
To open tmux In the terminal type tux and enter.
you should now see a screen like the one shown below:
With tmux open let's use our first command.
The above command will open a new terminal as you can see below in the screenshot. The new number for the bash window is highlighted at the bottom in green 0:bash 1:bash. Make sure to hold cntrl+b, release then type c. This is with all tmux commands moving forward.
If you would like to detach from a tmux session and go back to a normal session you can you:
From the screenshot below, you can see the output:
To see a list of your tmux session use the following command below:
And use the command below to attach to a specific session
tmux attach-session -t 6
Above you can see that we have reattached to session 6 as it shows in bracket .
If you would like to name sessions for better workflow you can use this command here. Replacing session_name with a name that you would like.
tmux new -s session_name
above you can see the newly created session name shells_session when using tmux ls
If you would like to completely end a session you can use the kill-session command using the following steps:
Another cool thing you can do is switch between the windows you created in your shell session using the command below.
To go directly to a terminal window session
CTRL+b "window number"
You can also split panes horizontally and vertically
Tmux is a really cool tool for the Linux admin. It allows you to multitask or close out a session without it killing the terminal so you can do backups or upgrade your system without having to leave a terminal open, just type your command hit CTRL+b then d, and walk away.