tmux, The Better Screen
Tags: [open-source], [linux], [software]
What is tmux?
Tmux stands for 'Terminal Multiplexer' and does a lot of cool things. If you use terminal often on your home PC or are using SSH to log into other machines tmux will be your new best friend. This is because when you use tmux you can have several terminal applications running in the same window. You then can switch between each with a key-combo that is customizable.
The real glory of this terminal app is when you are running a headless machine or are using SSH to run commands on another computer. This come when using the attach and detach feature that tmux provides. I used to use screen for this but I find tmux a much better option. After logging in all you need to do is type 'tmux attach' and the last session you had will display. You can also add '-t session-name' to call a specific session if you open several instances at a time.
I found that having multiple tmux session running does not gain me any benefit in my daily work but you may find a great use case for it. The whole reason I used tmux was to cut down on the number of terminal windows I needed to have open. The ability to switch between terminal apps with a key combination and not use the mouse or move my fingers off the home row is a huge plus.
Installing tmux is easy. If you are on Linux, chances are this program will be in your repository. I even remember it being in the Arch official repo back when I used that distribution. I also know for a fact it is in the Debian repos and all its successors, such as Ubuntu. For you Mac users, I believe you can get this through homebrew but you will have to double check as I use no Apple products.
Using tmux is a game-changer if you are the type who spends a lot of time in the terminal and even more so if you only have one monitor. So let's get into some of the cool things you can do with this application. Keep in mind that this is not an exhaustive list and you should look up the tmux manual if you are looking for an action not covered.
In tmux you have a key combination that lets the application know you want to a specific action. This is
ctrl+b by default and many people change this to an easier to reach option. My key choice is
ctrl+a and I find that most common but you can change that to whatever you like in the configuration file. When I call out this key combo, I'll be calling it
mod + so you are aware that you need to press whatever key combo you made the trigger. After the '+' will be what to press after to trigger the event.
Manage Your Sessions
Think of a session as a table at a wedding. Each table has its own number inside the venue just as tmux can have many sessions running at the same time. You can even name each session so you can remember what is in each.
If you want to start a new session with a name type
tmux -S and then what you want to call that session. If you are like me and only need one session open, after which you can type
tmux. To detach from your current session all you need to do is press 'mod + d' and this will take you back to your regular terminal. To attach a session type
tmux attach -t and the session name. If you are like me and use one session at a time you only need to type
tmux attach in your terminal.
To see a list of all your sessions type
tmux list-sessions into your terminal.
If the session is the table at the wedding than the tmux 'windows' would be the chairs around the table. Each chair is identical to the rest when placed but can hold very different things. When you first open tmux you will a bar at the bottom with the number zero and a word, 'bash' is often what you see if using Linux. You can change the name or you can leave it defaulted to change based on whatever terminal app you last opened.
To open a new window for increased multitasking all you need to do
mod + c once you are in tmux. To change to another window, you have just press
mod + and the number of the window as listed below. Tmux starts with zero so that can confuse people but you can change that if you wish.
To set a name that won't change press
mod + ,
I do this often since I use many panes at once inside each window and like to have the context of all the panes within.
Panes On Panes On Panes!
To continue with our analogy, a pane would be the dishes in front of the seats. Each dish is its own pane within a window. This not a perfect analogy at this point but works well enough. This is why I love tmux the most on top of the ability to detach from a session over ssh and come back to it later from another machine. Panes are just as they are in real windows. Often a grid shaped pattern of pieces of glass to make up the larger window.
When you start a new window in tmux you will receive one terminal taking up the entire screen. If you would like another terminal open next to that with press
mod + " and this will add another to the right as an even split down the middle. You can then add one below that with
mod + %. This now gives you a tall terminal on the left with two split terminals on top and bottom of the right side.
Ways to support the blog.
If you are an email kind of nerd you can sign up for mine here.
You can donate to this site from my Liberapay account if you so choose. If you want a more passive way to support this site, use this link when shopping on Amazon; it kicks some of Amazon's profit to me at no extra cost to you.