 Welcome to T-Mux. T-Mux is a terminal multiplexer. It enables a number of terminals to be created, accessed, and controlled from a single screen. And I frequently use it on this channel when I've done a lot of my tutorials or just talking about things like when I'm doing speed tests because I want to be able to log into more than one server at once to do speed tests or network tests or any network engineering. And the question comes up all the time, how did you split the screen? The answer is T-Mux. But that doesn't really explain how to use it. So I figured I'd do a video on how to get started with T-Mux. I'm going to show you the basics. And I really only use it for the basics. But those basics are really powerful and it's a great tool. Before we dive into the content here, if you can take a second to check out the affiliates over here we have on our channel and also link down below in this YouTube channel. This does help out this company and me producing content when you use some of these affiliates. And some of them get you some great deals including like the folks at Tech Supply Direct to have an offer code to get you 10% off. And the tree trial you can get with the folks over at IT Pro TV. We also have links to Inode, Digital Ocean, Google Fi and Amazon affiliate links. Like I said, all this to help out the channel. Or you can just hire us if you have some project you want to help us with or you need us to help you with. Said that wrong, but hey, why not? We can all work together. And others I hire us at the top over here. And back to the content. So a couple of things you want to talk about is T-Mux, the T-Mux cheat sheet. And of course my command prompt. Someone will say, Tom, your command prompt doesn't look like my default load of, you know, insert Linux distribution here. That is correct. This is a custom command prompt that I have. I'll show right here. And that is available on GitHub. And I bring this up related to T-Mux because I did customize my T-Mux config as well. So the T-Mux config actually I just updated today to fix the little network show at the bottom. I updated it, I changed it, but I do not in my T-Mux change the default key bindings because T-Mux being that it manages the window, it's like a window manager for the shell. I make sure to leave them at default. And the reason why is sometimes I have to work on other people's computers who have T-Mux installed and they have not customized it, which is fine. But if you start customizing the default keys, which you're gonna see control B use a lot. That's like how you kick off an action inside of there. And someone chooses a different command set. My fingers remember to type control B at the beginning. So I do leave that at default. But I do turn on mouse support because it makes it a lot easier. And generally speaking, computers, now we have a mouse handy. Now, mouse support is an add-on. Even if you don't have a mouse attached to the computer you're logging into, it doesn't really matter. It's only an add-on. And if you have a mouse, that function becomes available. It doesn't, it's not a necessity. Anyways, what is T-Mux in general? All right, so besides being a window manager and easy way to split windows, it's just a really great way to manage sessions when you're dealing with things like multiple servers, multiple computers and maybe waiting for things to complete. It's a nice session manager as well for things like that. I'm gonna first talk about screen key. Screen key and slop are tools I have. And what they do is they make this happen. You'll see things typing down here. I did this on purpose because when you're running T-Mux, which will actually exit out of T-Mux, whoops. Make sure I close all the windows I had open. So now cleared completely out of T-Mux. And it's important to see the commands I'm using because it's a lot of different keyboard shortcuts. So right here, it's just default load of T-Mux, which looks just like my bash shell, which may not look that much different to you. But you notice down here at the bottom, it has our local IP address, the time and the date and that we're using the bash shell. And we're gonna hit control B and a quote. And now we have two windows. And this is where the mouse support comes in handy to be able to switch between these two windows. So let's run something at the top window and we'll run something on the bottom window. So when you're here, I can use the mouse to select which one of these windows is active or live. So wherever which one is live, it puts a little bar there and then I can clear this one as well. How do you do it without the mouse though? So I don't usually use the mouse from selecting windows because the handy way to do it is control B, which is always what you start commands with. And then control B, let go control B and hit down arrow. So cow say bottom Tmux, there we go. So we have something in the screen. Control B up arrow, say top Tmux. So now we have something in the top and we can just switch between them. Control B up. Now, if you hold, if you hit control B, then quickly hit the arrows up and down, you can start resizing these windows or with the mouse support, you can drag them around too, which is really handy. Now that was a vertical split of the windows or let me see our horizontal split. What about if we wanna split the windows vertically? Control B percent. And all these are on the cheat sheet. Now this is one of the things I'm gonna mention. These commands seem weird. I don't know the reason why they chose like control B quote or control B percent to split them horizontally or vertically. I just know they did. Therefore, once you have all these committed to memory, this is why I say if you're changing the defaults and some people do, because they don't like those choices, you get confused when you start using someone else's session up to you. But that's one of the reasons I'm doing this at the default. So now if you wanna go left to right, we do this. And now we're in this pane and control B over here and now we're in this one. But what about if we split it both ways? What if we did this like that? Now how do we get there? Well, control B over always goes over here and control B over here, then we may have to go control B up arrow. It's gonna go between them depending on how it perceived that or once again, clicking in each one of them. So each one of these panes is able to run another process. Like I said, you can put H top back in this one here and then we can do something over here. Now this is particularly handy for like watching a log file as things are happening. So maybe I wanna run some utility. I'm trying to diagnose it over here but I want the log files to be rolling over here like while I restart SSH server or restart Apache. And then you maybe want to watch the log files roll by over here and you're doing it all in one session. This is one of the use cases I have or the other use case I have is I wanna go to another server. So let's go to SSH root at 192 and whoops. 192.168.3.4. I can be in my free NAS and I can run IPerf on my free NAS and we'll set it up as a server. Then we can go over here and then we can go IPerf3-client 192.168.3.4. So now I'm able to be on my local computer over here on the right, have my free NAS box here and I left htop over here so I can kind of see what's going on and I can get that dual view of something or I can like I said pull up log files. These are some of the use cases I have all the time for it and we can exit out of this and away we go. Now the other thing that can be done so we kick off some process to run in here. We'll run this one here. Run top here. And let's pull, let's do this. Curl. This actually will pull the weather up over in here and it will slide it over a little bit. There we go. Now it looks right. If you didn't know, WTTDR.IN, you can curl that right there and it will give you the weather. So all this is up and running. Let's detach from it. Control B, detach. I have released and now I can use, I can close the shell even, it doesn't really matter. So now we've closed it. So what happened? Is all that running in the background somewhere? Actually it is. That session is kept alive by Tmux. So if we go over here and we do Tmux A for attach, right back where we left off. Now, obviously it's not gonna survive a reboot of my computer because it's running on this computer but let's talk about when it's not running. So we'll exit, exit. And you'll understand in a second why this is important down here. So 192.1683.9. That's my local computer address. Now we're gonna go ahead and SSH over to my forums. So we're logged in to forums server. So let's kick off a Tmux session. All right. Yes, you can see this local public IP. This is the forums public IP address. So I'm logged in and I don't know, let's try to run one of the reports. So I'll ask, I have some go access. I think I've covered this in our video. This go access report takes a while to run. And while I just kick that off to run, we'll go down here and we'll kick off each top. And you can see it's gonna pin the process a little while running and this will take a while. But I need that report because I wanna know some of the log files and this is parsing all those log files. Gonna go ahead and hit control B, D for detach. And we'll even exit off the server. So now we've forums.loren systems closed, all right? So let's go back into the forums and we do Tmux A still running and this is great. Now, what about if the power went out on my computer? Like we just randomly and harshly disconnect the network and drop this connection right here. Well, then what? Close terminal got the warning. All right, so let's go back over here and we were SSH then then we were Tmux then. So let's go back in SSH forums. Back into the forum server and we Tmux A. Well, good news is the report completed but you can see the session is right where I left it. And that's an important aspect of this. So whenever I go and especially when I have to rebuild the forums as places I use Tmux a lot like from a business standpoint, it is all done in Docker and I do a get poll and get the latest Docker image and it takes a little while and it compiles and I don't want any of that output to get lost in case there was an error. So frequently without even opening up any more pains, I start Tmux, I start the update process which is actually I put a little shell script together for that. This is the discourse upgrade process. When I kick this off, it's gonna take a while and I don't want to risk if a connection gets lost on my computer or if I do this, for example, when I'm at home, I kick it off at home, then I disconnect the session, I come here to the office, I reattach that session and say, okay, what's the status of it? Is it done updating or was there some error message left on the screen that I can see? This is where Tmux is really, really helpful and also why I have this local IP display down here so I can remember what session you're on because the other thing about Tmux where things can get confusing is that's Tmux on there. So we're gonna close the forums, we're gonna fire up Tmux locally here. Then we'll put a bottom pane and we'll put a top pane and that'll, as I say, back into the forums. So now I'm on the forum server and what if we reattach on the forum server? Well, this is referred to as nesting Tmux so now we have Tmux running inside of Tmux and it'll work but this is also handy to have this little bottom. So I know locally I have my own Tmux server so if I do control B, split, it overrides and there's ways to go and override the override but it overrode and I'm actually on this computer here that control B gets caught by the first session of Tmux not the second one. So that's just something to note, you can nest it but I don't necessarily recommend it and that's more advanced use case but it does recognize typing exit and we can close all those sessions and now we're only back to my local computer over here. Now the other reason I mentioned mouse support is for the scroll back effect. What I mean by that is being able to type things like we'll go demessage for example and you're used to probably grabbing the scroll bar and going up but you probably notice there's not a scroll bar so let's just show you the difference real quick. So if we exit Tmux, we do demessage here. The bash window says okay, no problem, there's a scroll bar. That doesn't work that way in Tmux though. Tmux does have a buffer. It didn't go to DevNul, it went somewhere and the nice thing about having mouse support enabled I just scroll back with the mouse wheel real quick and I'm like, oh, that's what I was looking for this thing right here. Then part of the mouse support, we're gonna go ahead here and I'm like, there's that weird error message and I'm holding the shift key to do this because this works different than the shift key. There's a couple of different ways to do it. That's not the way to do it. So we actually wanna scroll back, find that thing you're looking for and go, all right, what is it? What's this OSMP? But what does that mean? So I'm holding the shift key, copy and then from there, as we all know, we just kinda go through and paste and figure out what those messages mean, whatever they are. But you can kinda get the idea. Now where this becomes really, really handy and we're gonna split it a little different here. So clear, SSH into the lab server. 3.134, so the top window is the lab server and the bottom window is my computer but I wanna actually log in the lab server again so I'm gonna go ahead and do that. So now I'm on the lab server here. Now maybe we're gonna go over here to slash far log. All right, what do we got here? Syslog, deep package log, maybe we'll look at the SSH log. Or actually authorization log. So we cat, auth log, right? So there's the auth log and maybe we wanna actually go a step further and watch it. And I've used this tool before, LNAV. LNAV auth log, all right. So LNAV will actually real time watch things. We're just gonna exit real quick. Remove session, start session and this is where Tmux becomes a really handy tool because you maybe wanna watch some log file and you wanna do something on that server and you don't wanna have to have two different windows open or things like that. Maybe you wanna split the windows. Matter of fact, you can even, while this is live, control B and we'll split it this way. It'll just move this over here. And now I have my local computer but let's SSH back into that lab. 8.3.134 and we're watching it over here exiting. So you're watching the logs over in this corner. You can see how this can be really handy to do it and especially when I'm setting up something that I wanna do a bunch of testing, now I wanna go, I wanna do this later. So control B, D, but I wanna get back to it. I want those sessions still alive because they're working on something. I can just Tmux-A and attach to it. But what, and this is where things get a little bit more advanced. So this is, we'll go ahead and attach all three. So I have three sessions all attached to one server in this particular Tmux session. We're gonna go ahead and control B, D for disconnect. We're just gonna fire up another Tmux. All right, and this is on my local computer. Cow, say some new session. And so we have more things on there. Why not do the curl weather thing again? So split here, move it up a bit like that and then we'll type curl, put the weather in. All right, so I got the weather displayed on this Tmux session. Now let's go ahead and control B, D for disconnect, Tmux LS. Now there are two sessions. Now this is where it gets kinda cool. If you do Tmux-A, A, it's attached to the other session but if we hit control B, S, we have a session manager. And for every version, or every, I'm not version, but every extra instance of Tmux you have, now you have, you can switch back and forth. Control B, this session, or this session. And these are all covered in a cheat sheet what I'm doing right here. So you can even just move to previous sessions, reattach and rename the sessions. It's really nice, LS was listing them from the command line when you're not inside a Tmux. Once you're in Tmux, it's aware of all the other Tmux sessions you spawned on your computer. So you can, again, it also allows the options to detach and move them. So this is actually just a really neat feature in Tmux, the fact that it's self-aware of all the other Tmuxes that you have running on your system and can keep track of them all. And when I exit out of this one and kill it, now we're back over here. It actually kills Tmux, but it only killed that session of Tmux. I can reattach to this session now. It's the only session live, so A only goes to this one. So it kind of gets you the idea, it sounds complicated at first, but once you're used to using it, it becomes a very handy tool for parsing out things, watching stuff that's happening, especially when you start doing stuff like checking log files. Having this ability to clear this and we'll exit out completely. So no more Tmux sessions now. And we go to root at 192.168.3.134. Clear, I just like to clear it to happen when I log in the servers. Now it's running Tmux. This bottom says what IP address I'm on. I know that's the lab server IP address and let's split the windows. Just using the split commands here. So now I have four windows running in here and maybe we want different things running in each one of these. So we'll have, this is where things get fun when you're doing some real heavy troubleshooting for a client and we'll do lnav, whoops, the syslog, s, then we'll go cd slash var log. Actually we'll just run lnav natively here. So it's gonna pull something different. When you're watching multiple log files, that's when things get fun slash var, whoops, log. What are we gonna go to here? This one would be maybe off log. So we can watch the SSH things in. And I have all these set up and let's say these are real specific ways I wanted it and I'm doing something with this box. Now I may want to control B, disconnect, exit. And this is kind of the same similar way of how I use the forums. I go back into that server. I can see my Tmux doing LS. There's that one session running. We'll go ahead and just attach to it. It's right where I left off. This happens frequently when you're trying to log something for a server. I just want the screen output on there all the time like this. Especially if I have a couple log files or sometimes even more and I've created some commands that are watching for something to happen when you're troubleshooting. It's really nice to leave this open on the server so you can just go back to it and just reattach to these sessions. Now the last thing I'm going to show you here that is kind of cool about Tmux. So besides all the other cool features, I have one, two, three, four panes all in the same place essentially. So how do we get to some of the other stuff like switching options inside of Tmux? Well, there's a whole command line system and we'll just cover it real quick through the cheat sheet. This allows you to get to this command, swap windows and things like that. Where's the other one we're going to use? Synchronize panes and then mode keys for when you want to be in copy mode and things like that. I like using the mouse because I think it's easier but these are options. There's also like just general option commands and this is how you get to those options. Like control B colon and then you set the option there. So let's go ahead and we're going to hit control B colon. And this is a neat option. I really like it. Set W, set W, synchronize panes on spelled properly. Now all the panes are in sync with each other. So LS does the same on all of them. We'll bring them all to the same directory, type clear, it's gonna, whoop, C-L-E-A-R, E-A-R, equal typo in all four panes all at the same time. And this is a neat way to be able to take servers and it doesn't all even have to be the same one. You can SSH to them because it's controlling it at the pain level. Maybe you're going in four different servers and you want to run the same command. Ansible is a better way to do mass commands and things like that. I have a couple tutorials on Ansible on my channel as well but for a quick way to do it and just say, I want to run this same command on these couple servers to get like a package installed. This is a quick and easy way to do it. You SSH in each one of the servers and we can then quickly add the same thing to each of them. And simultaneously, maybe we have too many windows open. If we type exit, it exited on all the panes at once. And now we're back to my local computer. And do I have any Tmux sessions? Nope, no sessions running. So we'll start a new one. And we're back to running Tmux on my local computer here. So print this cheat sheet out. This is what helped me get started in Tmux and it becomes kind of muscle memory for the most part. I had to stop and think to do this video like to some of the commands but that's also why I put them at the bottom. But you just got to remember control B to get a lot of things kicked off. These are like the renamed sessions, control BD. Control BD and control BA are the two I learned a lot. So control B, like to switch the session or detach from a session and control B, A to attach. I'm sorry, Tmux A to attach and control BD to detach Tmux A. Said it wrong, you don't need to control. You're just typing Tmux A to get it back on there but control BS will cycle between many sessions you have of Tmux up and running like I showed earlier. So there's a lot to it but you don't have to be too intimidated. If you just want the basics of splitting the screen and being able to log in a couple of different places that is easy to do with just splitting the screens with those couple of basic commands. And it's actually what I use it for more than anything else but you can quickly become a power user. Also this has searches on here too so you can find different stuff. I thought it was kind of neat but either way just having a copy of this is really handy to kind of learn how some of it works. You can dive way further into Tmux and start playing with it. It's a really powerful tool and a lot of my friends who are developers in Linux have been using it for a long time. That's how I got intro to it and figured I want to share it more. It's a great tool and go out and apt-get install it if you're on Debian or any other systems that it's supported on, thanks. And thank you for making it to the end of the video. If you liked this video, please give it a thumbs up. If you'd like to see more content from the channel hit the subscribe button and hit the bell icon if you'd like YouTube to notify you when new videos come out. If you'd like to hire us head over to laurancesystems.com fill out our contact page and let us know what we can help you with and what projects you'd like us to work together on. If you want to carry on the discussion head over to forums.laurancesystems.com where we can carry on the discussion about this video other videos or other tech topics in general even suggestions for new videos they're accepted right there on our forums which are free. Also if you'd like to help the channel in other ways head over to our affiliate page we have a lot of great tech offers for you. And once again thanks for watching and see you next time.