Kurs obsługi TMUX od NetworkChucka (film, 18 minut)
W filmie NetworkChuck omawia potęgę narzędzia Tmux, nazywanego terminalowym multiplexerem, które staje się nieocenionym towarzyszem dla każdego, kto pracuje w terminalu. Tmux pozwala użytkownikom na uruchamianie wielu sesji, okien i paneli w tym samym terminalu. To niezwykle użyteczne dla programistów i administratorów systemów, gdyż umożliwia łatwe przełączanie się pomiędzy róznymi zadaniami, nawet jeśli użytkownik rozłączy się z sesji SSH. NetworkChuck pokazuje, jak szybko można tworzyć nowe sesje w Tmux i łączyć się z nimi z różnych lokalizacji, co z pewnością wydaje się super mocą.
Muzyka tła w filmie pomaga obrazować entuzjazm NetworkChucka w prezentacji Tmux. Osoba ta nie tylko podkreśla prostotę instalacji i używania Tmux, ale także intensywność, z jaką można pracować przy jego użyciu. Dzięki prostym komendom, takim jak "tmux new -s nazwasesji", użytkownik łatwo tworzy nowe sesje, może je nazwać i zarządzać nimi bez obaw o ich trwałość. Co ważne, użytkownicy mogą odłączać się od sesji, a następnie powracać do nich w dowolnym momencie bez utraty danych, co czyni Tmux idealnym narzędziem dla zapracowanych profesjonalistów.
W miarę postępu w filmie, widzowie uczą się, jak korzystać z różnych funkcji Tmux, takich jak dzielenie okien na panele, zmiana ich wielkości oraz poruszanie się pomiędzy nimi. NetworkChuck tłumaczy, jak nawigować po sesjach, oknach i panelach, wykorzystując proste skróty klawiaturowe, co sprawia, że każdy nowy użytkownik Tmux może szybko przyzwyczaić się do jego używania. Zachęca również, aby przekonać się, jak Tmux może zwiększyć produktywność, poszerzając horyzonty użytkownika i umożliwiając jednoczesne monitorowanie wielu zadań.
Film kończy się refleksją o tym, jak złożone może wydawać się Tmux na początku, ale po kilku próbach staje się przyjemnym narzędziem do pracy. NetworkChuck przekazuje cenną wiadomość, że najważniejsze to praktyka, a efektywne korzystanie z tej technologii zapewnia większe możliwości w codziennej pracy. Zachęca widzów do eksperymentowania i nauki wszystkich funkcji Tmux, aby zwiększyć swoje umiejętności w terminalu.
Na czas pisania tego artykułu film osiągnął około 670634 wyświetleń i 23413 polubień. To świadczy o dużym zainteresowaniu tematem, a także pokazuje, że wielu ludzi zaczyna wkraczać w świat Tmux dzięki NetworkChuckowi. Jego podejście do nauczania, które łączy entuzjazm z praktycznymi poradami, czyni z niego doskonałego nauczyciela dla każdego, kto zaczyna przygodę z używaniem terminala i systemów Linux.
Toggle timeline summary
-
Wprowadzenie do Tmux i jego konieczności.
-
Szybkie logowanie się do serwera Linux za pomocą Tmux.
-
Uruchamianie nowych okien w kilka sekund.
-
Odłączanie i ponowne podłączanie do sesji SSH.
-
Przedstawienie Tmux jako twojego nowego najlepszego przyjaciela.
-
Opis Tmux jako multiplikatora terminali.
-
Zaczynamy korzystać z Tmux na ulubionym przypadku użycia.
-
Rozpoczęcie nowej maszyny wirtualnej.
-
Podkreślenie korzyści z używania Linode.
-
Dostęp do serwera przez SSH.
-
Sprawdzanie, czy Tmux jest zainstalowany.
-
Rozpoczęcie nowej sesji Tmux.
-
Wykonywanie ciągłego pinga jako praktyczny przykład.
-
Odłączanie sesji Tmux.
-
Ponowne podłączanie do istniejącej sesji Tmux.
-
Wyjaśnienie pojęcia sesji Tmux, okien i paneli.
-
Tworzenie nowej sesji Tmux z określoną nazwą.
-
Wyświetlanie bieżących sesji Tmux.
-
Zabijanie określonej sesji Tmux.
-
Wprowadzenie do trybu kopiowania w Tmux.
-
Używanie skrótów klawiaturowych do kopiowania tekstu.
-
Podsumowanie funkcjonalności Tmux i uwagi końcowe.
Transcription
You need to start using Tmux right now. Check this out. I'll log into my Linux server in the cloud with one command. Craziness happens. In seconds, I can launch new paint, new windows. I can detach and end my SSH session, run home, pull the different computer, and reattach to that same session. It's a superpower. Now, I'm not new to Tmux, but now, now we're best friends. So allow me to introduce you to your new best friend, Tmux. We call him T for short. No, we don't, we don't do that. Tmux is a terminal multiplexer, which makes me think of Ghostbusters for some reason. I don't know. It's a program that runs inside of your terminal and allows other terminal programs to run inside of it. Your brain hurt? Mine does. Now, to learn Tmux, we're just gonna start using it. And we'll start with my favorite use case, what I showed you in the intro. Being able to run something in your terminal, leave it, or detach from it, and reattach to it from somewhere else. Come back to it later. That's amazing, right? So let's do that right now. Now, first, of course, you'll need some kind of Linux computer. It can really be anything, but for me, I wanna use a cloud machine. It's what I use all the time. So I'll spin up a new Linux virtual machine in the Linode Cloud by Akamai. They're the sponsor of this video. I love them. They're my favorite cloud. Because I can do stuff like this, just quickly launch a virtual machine in seconds that I wanna play with. Let's do the latest Ubuntu. Five bucks a month. I'll label it and create it. Now, if you're like me and you're always doing a bunch of Linux projects and you gotta spin up those Linux machines fast and have it always available and possibly public, Linode's your friend. As you can see, I've got so many virtual machines, it makes me wanna cry. Because it's so awesome. But seriously, if you wanna try out Linode, I highly recommend them. I've got a link below, linode.com.networkchuck. And if you're new to Linode, you'll get $100 credit for 60 days. So whatever you wanna do today could just be free and for 60 days. Anyways, my machine is done brewing. I'm gonna grab my SSH access command right here, launch my terminal in Windows, paste my access command and get logged in. I'm in. First thing we'll do is make sure that tmux is installed. Now, the good news is that tmux is installed by default in a lot of places. Mine is already installed. Awesome. So apt install tmux. I'm gonna make this a bit bigger. And then finally, to start what's called a tmux session, all we'll do is simply type in tmux, just like that, and hit enter. This is a terminal running inside your terminal. It's like terminal virtualization. Like it, not is it. Don't ping me that. I don't wanna see a comment like, actually, Chuck, it's not virtual. Let's do something fun. Let's just do a continuous ping, which is the default on Linux. We'll just do ping networkchuck.coffee. Make sure my coffee site is up. Certainly is. You should go check it out. Now, you don't have to copy me, but allow me to show off real quick. Ready, set, watch this. Bam, bam, bam, bam. I just created a bunch of pains. And a real life example of how many cups of coffee I drink in a day. It's still going. So now what we wanna do is detach from the session, not end it, not end anything. Well, I want everything to still run, but we're gonna just detach. To do that, and you'll learn more about this here in a second, I want you to hit control, hold it down, control B. Nothing happened, right? Don't worry. Don't do anything. Now press the D key. That's it. Control B, D. We're detached from that session and it's still there though. That's the good news. Let's reattach to it. One simple command, tmux, A. Just where we left off. It's still going, 35 cups of coffee. It doesn't matter if you lose internet connection and get disconnected, or you wanna go home for the day and resume somewhere else. Tmux will still be here for you because that's what a best friend does. I told you, tmux is your best friend. ♪ Natural friend ♪ Should we get tmux tattoos? We'll think about it. But seriously, you don't wanna stop here. There is more awesomeness to behold. Here's the rabbit hole. You wanna go deeper? You wanna take the, is it the blue pill? Take the blue, the red. I always forget which pill it is. Actually, don't take any pills. Just have some more coffee. By the way, have you hacked the YouTube algorithm today? Let's make sure you do. Hit that like button, subscribe, notification bell, comment. You gotta hack YouTube today. Ethically, of course. Anyways, tmux, the deep dive, semi deep dive. I'm just gonna detach from this. Control B, D. Now by the end of this video, you'll pretty much be a tmux expert. And trust me, it's gonna pay off. Anyways, here we go. Tmux, it has three layers. First, we have the session, which is what we just created when we used the tmux command up here. That created a session. Notice how when we detach from it, it said detached from a session. Let's go ahead and do that now. Again, type in tmux, new session. And actually, if you wanted to customize it a bit, so let's hit Control B and D to detach. Let's create a new session and name it. So tmux, this time we'll have to add some things like new. And then we'll do a dash S for session and name it. Let's name it Bob. Just like that. Bam, new tmux session named Bob. You can see his name right down here in the bottom left corner. Now let's detach from Bob. So Control B, D. And at this point, we have a number of sessions up and running. Like we didn't stop them. We didn't kill them. We just detached. How do we see those sessions? With this command, tmux ls. Just like you list your files, this is how you list your tmux sessions. Hit it. Bam. We have three sessions. Two are defaulted named. We just typed in tmux. The third one is Bob. I love Bob. Now, as we saw earlier, we can reattach to our tmux session with the tmux a command, which a is short for attach. This will attach us to our most recent session, which is Bob. Let's go say hi to Bob. Hello, Bob. How do we know it's Bob? Bottom left corner, Bob. Let's back out of Bob once more. Control B, D. Now, notice we're getting some practice here, and that's kind of what tmux is all about. Initially, it's gonna be like, what is going on? Why are there so many keys I have to memorize? It's all about practice. And maybe you don't realize this, but right now you've been attaching and detaching. It's kind of becoming second nature to you, right? That's how tmux will be when you practice. Let's continue. Now, what if we don't want to attach back to Bob? What if we want to attach back to the first session we made with all that awesome stuff in there? It was our ping, right? So to specify the session we want to attach back to, it's just one more little switch. So tmux, A. Then we'll do a dash T to target what session we want to connect to. And we'll just say the index of that first session. Zero. Ready, set, attached. There's all our stuff right there. 326 cups of coffee. Almost caught up for the day. Let's control B and D to detach. Now, what do you say we kill Bob? I know. I'm sorry, Bob. Man, I hope YouTube doesn't ding me for that. YouTube, it's just the tmux session. That should do it. So here's how we do it. tmux, kill-session. Now, just that alone, that command by itself will kill your most recent session. We don't want to do that. We want to be specific. We want to kill Bob. So we'll do a dash T to target Bob. And then type in Bob. Goodbye, Bob. Bob is gone. Type in tmux ls. We only have two sessions left. Now I kind of miss Bob. Let's create him again. Do you remember how to do it? tmux new dash S, Bob. Bob is back. Let's have him do something. Let's have him ping networkchuck.com. Nice. IPv6. Control B, D to detach. Now let's talk about our second layer, the window. When we create a new session, by default, a window is created. Like watch this. Let's create one more. We can make as many as we want, I think. I haven't tested that yet. Type in tmux new dash T, and we'll call this one Stacy. So with that one command, we created two things. We've got our session and we have our window. The session is Stacy right here. The window is Bash right here. Index zero, Bash. That's the name of it. Why? Well, it's because it's the program we're using for that window. And that's what it will default to. Now, where's the, where's the window? This whole thing is the window. This whole area. Our third layer is panes, where we can split our terminal into little bitty pieces. Now to do this is going to start our journey of learning the hotkeys. It's not too bad. It's going to be fun. You'll feel like a wizard. Seriously, let's do our first one. So the goal here, and say goodbye to our drawing, I'm deleting. The goal here is I want to split my terminal horizontally or hotdog style. Let's do it. The hotkey will be control B, hit that control B, let it be. And then we'll do a percent sign. So shift five, boom. You see that? A new pane. Kind of killer, right? Let's do it again. Control B, percent sign. Bam, another pane. What do you say we do a hamburger style? Control B, and then we'll do double quote. Shift, double quote. Bam, hamburger style or vertically splitting. Now, before we move on, let's cover this whole control B business. What is that? Control B is what's known as our prefix key. When we hit it, TMUX is like, oh, what do you want me to do, boss? I'm ready. I'm ready. What do you want me to do? I'll split it vertically, hotdog style, hamburger, whatever, I got you. Any of the hotkeys we've mentioned here in this video can be changed. I like sticking to default. So no matter what system I hit, if I install TMUX, I don't have to redo anything. And what happens after that are things like, you know, we hit D to detach, or you might hit the percent sign to create a new pane. Hotdog style. Now I'm gonna do you a favor. As you look up TMUX documentation, you're gonna see it written like this, C-B. Just know that when you see C-B like that, it means control B or whatever your prefix key is. Just keep it control B, keep it simple. And then right after that, you'll see the letter or symbol you want to press, double quotes. Okay, so we got the prefix key down. Let's get back to our panes. Now notice here, if I start typing, I'm in the pane over here, obviously. I can also tell that by the highlighting. The pane is highlighted green. That is green, right? Hi, Logan Paul. I'm colorblind. So to move around, we're gonna hit our prefix key, control B, and then your directional arrows. Up, down, left, right. Which way do you want to go? Let's try up. Just gonna hit the up arrow. Bam, we switched. Now if I try to hit it again, no, we're out of prefix mode. It's not gonna do anything. Now also, if you're fast enough, if you hit control B, you can move around before it times out. Notice how I'm like jumping around. But then if I stop for a second, it stops. So kind of fun to switch around. Now I think the best way to move around your panes though is with control B, Q. Check this out. I'll hit control B, Q. Did you see that? Watch this. It displayed the indexes of my panes. Each pane has an index. Zero, one, two, three. And I can use that to jump into any one I want. So if I hit control B, Q again, I can see, okay, two is on the right. Now I can hit control B, Q, two, and I jumped there. You have to be fast, but that's the whole goal, right? Control B, Q, one. I switched to this pane. Now I'm gonna switch to this guy right here. Control B, Q, zero. Oh, I wasn't fast enough. Let me try it again. Got it. That's kind of cool. Now you can also change the size of your panes with this hotkey. You'll hit control B, like everything, but then you'll hold down control and using directional arrows, it'll change how big your active pane is. Let's switch around. This is directional arrows. Any direction you want, you can change the size. Pretty cool. If you wanna make bigger steps, you can do control B and then alt over, over, over, over. So holding down control or alt will help you resize your panes. It's kind of a pain. Sorry. Could help myself. Now my favorite thing though, if you don't wanna sit here and resize all your panes, is you can do a preselected layout. Check this out. Control B, like always, and then alt one. Look at that. Four vertical panes. Let's try it again. Control B, alt two. Huh, control B, alt three. That's just ugly. Control B, alt four. That's cool. Control B, alt five. There's five options. But those are preselected layouts that'll just put your stuff really nicely if you're just kind of lazy, like me. Now we've been talking a lot about panes and we kind of just brushed over windows. And currently we only have one window. Can we have more? Yes, we can. Let's create a new window. To do that, any guesses how we're gonna start? Control B and then just simply hit the C key. Bam, we have a new window. Let's do it again. Control B, C. Another window. Control B, C. It's addicting. Let's keep doing it. Also notice we can see our current one by the asterisk. So we're in our sixth window. How do we jump around? How do we get back to our original window? How do we move around? This command or this hotkey. Control B and N will just move you sequentially through your windows. Control B, N. Notice my asterisk jumping. Control B, N. Control B, N. Wait, no, that's not what I wanna do. There we go. So we're back at five and I really, really hate that it's not named anything specific. Let's change that. To change the name of our window, right here while we're active. Control B, comma. And just right here we get a dialogue. Hey, do you wanna rename your window? Sure do. Let's name it Linode. Bam. Number five is Linode. We got it. Let's rename the rest. Cool. The gang's all here. We renamed them all. Now I gotta admit, moving around with Control B, N sequentially is really annoying. I hate it. There's a better way to move around and it's amazing. You'll be mad at me for not even showing you this first. You ready? Hit Control B and then W. Are you seeing this? Not only is it a list of our windows, we also have a list of our sessions. There's our first one, our second one. There's Bob. Good old Bob. We got Stacy. We can jump to each individual window and look at it. What's going on? And just by hitting Enter, we can jump back in there. How cool is that? Control B, W. Awesome way to move around. So powerful. Are you starting to see the power of Tmux? I mean, yeah, it's kind of like a, oh my gosh, all the hotkeys. This is kind of painful. But once you learn them, you're a wizard Harry and you just are. So what you've learned so far is a lot. Like you learned sessions, which we can have multiple sessions. You'll learn Windows. We can have multiple windows. You'll learn the pains. This will make you so hyperproductive with Linux. No matter what you're doing, whether you're a programmer, a hacker. I mean, just imagine you're doing an in-map scan. You switch out and you do Metasploit. You jump out, you're running Subfinder or some other subdomain enumeration tool. Have those running detached. I mean, it's just, it's cool. Now we have all these pains, windows and sessions. Let's talk about killing. How do we kill them? How do we get rid of these guys? We've created them. We've created our monster here. How do we end them? Now first we can do it from this view right here. Our Control B W view. Simply highlight one. Let's pick Ronald Weasley. Hit Control B, our prefix key, and then the letter X. Now at the bottom, you're gonna see, hey, do you wanna, do you wanna kill this pain? Are you sure? Yes, I do. Type in yes. Goodbye, Ronald Weasley. Notice he's no longer at the bottom list here. He's not there. But if we go to one that has multiple pains, like the OG. Whatever highlighted pain I have. Hit Control B, X. You wanna kill this pain? Yes. Kills that one pain. What if you wanna take out this entire window all at once? Control B, ampersand. Really fun to say. Say it, ampersand. Do you wanna kill the window? Type in yes. It's gone. The OG has been eliminated. I'm sorry. And then of course, if you wanna back out, Control B, B to detach, Tmux LS. We can terminate any of these sessions, taking out the entire thing. Windows and panels and, panels, screens and all. I'll have all these commands down below. I'll also link some fun Tmux cheat sheets that are very helpful. I haven't shown you everything, but I've shown you enough to kind of be an expert and be dangerous. But there's one more thing, if you wanna stick around. There is something called copy mode, which makes copying text ridiculously easy and working with it really fun. I mean, you've made it this far. Let's keep going. Let's jump into one of our sessions. Tmux. Hey, we'll jump into dash T. We'll jump into bot. Oh, bot was still pinging, man. Now, before I show you copy mode, there is one thing I want you to do. I want you to change something about your Tmux config file. Without doing this, it becomes pretty annoying. So, real quick, we're gonna adjust the Tmux config file. We're gonna type in nano, the best text editor in the world. Maybe. I'm thinking about making a VIM video because I need to learn it. I know, I know. Anyways, let's continue. Nano, this will be in your library. So the tilde forward slash dot Tmux.conf. Just like that. That file may not be there. That's fine. We're creating it right now. We're gonna add two lines of config. First, we'll type in set-g mouse on. That's gonna make some things easier for you if you're lazy and don't wanna be super fast. This one, though, is gonna make you amazing. Set-w-g mode-keys vi. That's gonna enable some VIM superpowers. Check it out. It's gonna be amazing. Control X, Y, enter to save. Now, watch this. I'm gonna kill all my sessions all at once. The best way to do that is Tmux kill-server. If you do an ls, everything's gone. Let's do a quick little session in Tmux. I will ping something. Let's get some text on the screen. Now, with my mouse, I can just simply highlight. Now, notice what's happening here. Notice the top right. We have like a special little zero, zero menu. We're in copy mode. And when I release, we're done. That's probably the easiest way to copy with Tmux. That line of config, the set-g mouse, whatever that was. We can easily just highlight anything and then just paste it. That's super handy. But I'm really against that because the goal with Tmux and really anything in the terminal is that your hands never leave the keyboard. Glue them to your keyboard. The second you have to reach over and grab your mouse, you're slow. That's valuable seconds you don't wanna lose. So instead, we'll use copy mode from our keyboard. To enter copy mode, Control B, big surprise there, right? And then opening bracket. Bam. Notice, top right, things changed. Now, using our directional arrows, we'll jump to where we wanna start copying. Let's say I wanna start copying right here, all the pinged statistics. Easy for me to say. Where I wanna start, I have my line, my cursor. I'm gonna hit space. Starting there. Cool. I'm just gonna move along. Using my directional arrows, I'm moving until I reach the end of what I wanna copy. Right here's good. Then I'll hit enter. Bam. That's been put into my copy buffer. Now to paste, I'll do Control B, closing bracket. Just like that. That's copy mode. Let's try it again just to make sure we have it cemented. I'll hit Control B, opening bracket. Go to where I wanna start. Hit space. Move around. Now you can use your directional keys or you can use some Vim keys like H, J, K, and L. I'm not gonna cover that right now. We'll keep it simple. Hit enter to stop and then Control B, closing bracket to paste. Now we just covered pretty much everything you'd want to know about Tmux. You don't have to use all the Tmux features. If all you cared about was the attaching and detaching and you treat it like a normal terminal, that's a win. What do you think of Tmux? Are you gonna start using it? Have you already been using it? Let me know in the comments below. That's all I got. I'll catch you guys next time.