Sun. Nov 10th, 2024

tmux is a an open source terminal multiplexer. In the language of laymen, tmux allows you to run multiple terminal sessions which you can access through the same ssh connection, or any type of terminal session you might be running to access or administrate your system. You can think of it as a window manager for console based connections. It allows you to run several commands in their own terminal window so you can multitask in an efficient manner. There are other ‘terminal multiplexers’ available for Linux/Unix systems such as screen, byobu and wezterm, among many others. I personally prefer tmux as I have been using it for years (I use to be a GNU screen user but switched as tmux is a little more feature rich) however this article could apply to any terminal multiplexer.

I generally use tmux when I need to concurrently watch several terminal sessions for the purposes of troubleshooting, comparing configuration files side by side, or if I’m juggling a bunch of processes in my mind and need a physical representation of what’s going on so I don’t forget/lose my thoughts. I’ve come to rely on tmux as the penultimate troubleshooting tool for keeping my sanity. 😉

As an example, I’ve included as the picture for this article a tmux session I was using to troubleshoot a sendmail issue. As you can see from the picture, the screen is logically divided into 4 sections with each running it’s own bash shell. Starting from the upper right ‘window’ and going left we first have a terminal session with a root prompt waiting for me to do something. Next to that ‘window’ is a tail -f (Linux/Unix program) of the mail log. In the two lower ‘windows’ we have journalctl -f running to monitor system logs and finally a tail -f of the fail2ban system log. This allows me to monitor all of those processes in real time and watch as connections come into the server, note errors logged if there are any and monitor the fail2ban process in the lower left window for additional information which aided in troubleshooting of the mail issue.

This should be familiar to anyone who runs Windows who may have used multiple Putty (Windows ssh client) sessions to troubleshoot issues or Linux GUI users who run multiple terminal sessions to perform the same thing. tmux, or any number of windows or terminal based session keepers are not limited to troubleshooting, as I’m doing in this case. Troubleshooting just happens to be the primary reason I use it, so I don’t have 4 or 5 Putty or terminal sessions going on my desktop. It’s basically just windows in windows logically connected to perform some task which in this case is troubleshooting.

I generally write these articles as informational pieces without too many actual commands but I’ll give a short and sweet introduction on how to use tmux.

Just type ‘tmux‘ in your shell and a shell will start with a status line at the bottom of the screen (usually green). If your system comes back with command not found, use your system facility to install it. on Ubuntu apt install tmux. The most important key sequence to remember is ‘ctrl-b‘. That puts tmux in command mode. After that you can do ‘shift-“‘ (that’s shift-double quote) to create a window side by side (horizontal). You can also do ‘shift-%‘ which will place a window in the in the up-down direction (vertical). To move between the windows it’s as simple as going into control mode (‘ctrl-b‘) and using the cursor keys to navigate to which window you need to get to. You quit tmux by logging out of all the terminal sessions. tmux has many other options such as saving a set of windows with running processes so you can re-attach to the sessions at a later time or having windows continue to run in the background when you logoff. I’ll leave it to you to go over tmux documentation to learn how to do that.

This article presented the screen multiplexing utility tmux, one of the reasons I personally use it, and a short and sweet presentation of a few of the commands so you can give it a try. If anyone would like me to write a more technical account such as howto’s with step by step commands, please leave a comment or send an email to ronald.johnson@zettabytes.org.

By editor

One thought on “tmux – Windows for bash”
  1. Pretty kewl. I’m glad you added those few commands so we could give it a try. I think if those were the only commands you knew in tmux it would be enough.

Leave a Reply