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.
Installation
Let's go ahead and select the icon and search for the terminal in the search bar 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
Running your first tmux session
To open tmux In the terminal type tux and enter.
tmux
you should now see a screen like the one shown below:
With tmux open let's use our first command.
Crtl+b c
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 1:bash. Make sure to hold cntrl+b, release then type c. This is with all tmux commands moving forward.
Detach from a session
If you would like to detach from a tmux session and go back to a normal session you can use the following command:
CTRL+b d
From the screenshot below, you can see the output.
Reattach to a session
To see a list of your tmux session use the following command below:
tmux ls
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 [6].
Create a session name
If you would like to name sessions for a 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
Killing a session
If you would like to completely end a session you can use the kill-session command using the following steps:
CTRL+b :
kill-session
Switching between terminal windows
Another cool thing you can do is switch between the windows you created in your shell session using the command below.
CTRL+b w
To go directly to a terminal window session
CTRL+b “window number”
Splitting Windows
You can also split panes horizontally and vertically
Horizontal split
CTRL+b %
Vertical split
CTRL+b “
Other commands you can use with tmux:
- Ctrl+b , Rename the current window
- Ctrl+b o Go to the next pane
- Ctrl+b ; Toggle between the current and previous pane
- Ctrl+b x Close the current pane
Conclusion
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.
Comments
0 comments
Please sign in to leave a comment.