i created 1 MILLION directories in Linux!! (will it die?)

Video Notes:

Access your FREE Linux lab here: https://bit.ly/3FJOXnN (HTB Academy)

Have you ever wanted to destroy Linux or even create more directories than you could imagine? Well in this video, NetworkChuck shows you how to break your linux box as well as how to create a million directories!! He also shows you some helpful commands too…. But we know why you’re here.

Checkout HTB:

-HTB: https://bit.ly/3dZ31NF

-HTB Academy: https://bit.ly/3q80iqC

🔥🔥Join the NetworkChuck Academy!: https://ntck.co/NCAcademy

**Sponsored by Hack The Box

0:00   ⏩  Intro

0:57   ⏩  Get your free Linux lab!

2:10   ⏩  Let’s get to our happy place!

2:22   ⏩  Time to touch some files

3:30   ⏩  a new way to use cat?

4:43   ⏩  echo “How to use echo to create a file with text inside” > Thistimestamp.txt

5:49   ⏩  Now let’s make some folders… I mean directories

7:36   ⏩  Time to mv some stuff

10:53 ⏩  You can’t cp this!

12:36 ⏩  How to make a million directories!

15:38 ⏩  Ready to destroy some stuff?

20:05 ⏩ Time to really make a million directories!

21:51 ⏩ Outro

I created over 1 million directories in Linux with one command. Why? I don’t know. I just wanted to see if I could do it, but seriously, how many directories will it take to break Linux? I wanna find out by the end of this video, but first I’m gonna show you how to actually make directories, how to create them, create lots of them, and also how to create files. You see, this is more than a stupid, uh, something really cool video. This is gonna teach you something you’re gonna learn. I’m gonna force you to learn. So get your coffee, ready time to learn some Linux and watch me do something stupid. 

Now, before you ask, yes, I actually did create over 1 million directories in Linux and yeah, it kind of broke things. So you’re probably wondering, well, Chuck, why would you do that to your own Lennox computer? And I’ll tell you, I didn’t. This computer belonged to hack the box academy, the official sponsor of this entire series, and the reason you can have a free lab right now that you can break yourself. Do you wanna break some Linux with me? Let’s break, hack the Box’s Linux. Seriously, check the link below, get signed up. It is absolutely free. And once you’re registered and signed in, you can go to modules, all modules, Lenox fundamentals, and launch your very own Linux box. You can break right now. Now there is more to hack the box academy. They have pretty much everything. You need to become a hacker from all the crazy modules that teach you some pretty dangerous things, almost two dangerous, but also some defensive things to protect your systems, red team, blue team. 

And then my favorite thing are their paths. They have both skill paths and job role paths. So if you want a job in, uh, cybersecurity, check this out. Bug bounty hunter, junior penetration tester. Look at these modules. They get you ready. And speaking of bug bounty hunters, they now have a certification. If I go over here to exams, they have a hack, the box certified bug bounty hunter certification, kind of crazy. So if you do wanna become a hacker, check out a hack, the box academy. In the meantime, let’s get our lab going because you already signed up cuz it was free. It’s right below in the description. Just do it. Quick coffee break, go and start your lab, your workstation, your phone box, and then click on interact to make it big in its own window. Our Linux box and the cloud that we can break. 

Now, before we break things, we’re gonna actually do some things. We’re gonna learn some stuff and then we’ll break it. Okay. Build it, learn it, break it. Pitch wisdom for the kids. Now, if you’re new here, the first thing we always do is launch our home, our terminal, our happy place. Launch that guy right up there. Oh yeah. The bass shell I’ll make things bigger with control shift. Plus we learned that in the previous episode. Now the first thing I wanna show you is how to create files and Lennox. If you’re thinking Chuck that’s so basic and easy, I bet I’m gonna show you something that you don’t know. So even you Lennox, veterans, hang tight, take a sip of coffee. You’re gonna learn something. I hope first we’re gonna touch some things. Don’t get weird. We’re just gonna do it right here. Type in touch. 

And then the name of a file. Can’t touch this dot TXT. Just hit enter. There. It is a file we just created, but it’s empty. If we look inside of it, we can do that right now with a cat command cat, can’t touch this. We need a tab to auto, complete nothing inside. We could also touch a lot of things. We can create multiple files at one time with touch, check it out, type in touch, and we’ll create four files right now. Can’t touch this. Yes, bam. I just created four files. If I hit LS there, they all are 1, 2, 3, 4. Okay, cool. We created files. We touched a bunch of stuff, but they’re all empty. What if we wanna create some files with some stuff in it? We can do that with a lot of things actually. But did you know you can do it with the cat command so we can use the cat command to look inside these files, but we can also use cat to create files with stuff inside. 

Watch this. Let’s clear our screen control L and this is pretty cool. It does make things faster, a little faster, but we know from the last video little things that make us faster, equal to big things that make us, we’re just, we we’re really fast. <laugh> okay. Type in cat, do the right arrow. And the name of your file. Let’s do file dot TXT hit enter. And right now it’s waiting for us to put stuff inside of it. Like, Hey, I’m putting stuff inside of it. And then I’ll hit control D to save it. And that’s it. Now, if I cat that file actually cat the file. Cat file at TXT. There it is. So that’s pretty cool. And lemme show you one more way. We can do this with cat and this comes in handy when you’re writing bash scripts. So we’ll type in cat, we’ll do two back arrows or whatever the crap those are called. 

And then we’ll type in E O F. Now this can actually be anything, but this is the most common thing we do. It stands for end of file. And then we’ll do a right arrow. And after that, we’ll put in the name of our file. Name of our file. That’s TXT and hit enter. Now what’s happening here is kind of cool. I can do lots of stuff. Multiline go crazy. And it will keep doing stuff until I say this E O F at the very end and hit enter. And it’s done. So notice what we did here with this weird little syntax. We said, Hey, when we type in E O F and enter, that’s the end of it, that’s done that signifies the end of our file. And again, I mentioned that could be anything like watch this instead of EEO F I could have it be cat and I can type stuff and then end it with cat. 

So that’s pretty cool. And then just when you thought you were sick of creating files, Chuck had one more to show you. And I like this one, cuz we can create something in a file with one line quick, bam, watch out here we go type in echo and then whatever you wanna put inside your file and then the right arrow and the name of the file and that’s it hit enter and it happens. So if I cat that file cat stuff, dot TXT, there it is so simple. One liner to quickly add up, create a file with something inside of it. I like that. So touch cat echo, and probably have a bunch of other ways we can create files. And the reason I’m showing you all these is you’ll probably end up seeing these in scripts or using them yourselves in a lot of situations. 

So you just have to know it, just be familiar with it. Okay. Now for the fun stuff, we’re moving on to directories. You know what that means? So real quick type in LS. Let’s do LS dash L and right now, ah, the, all these little files are kind of cluttering up my home directory, my sweet home Tilda. So what do you say? We created directory to put all them inside and get them out of the way. Now, if you come from the windows world, a directory is basically a folder just don’t ever, ever say that in this context or they will kill you. Just kidding, kind of, but that’s what a directory is. It’s a folder. It holds stuff. Now. I don’t know why we couldn’t just agree on one term. I don’t know if windows is wanting to be different or Linux was wanting to just be different and cool. 

I don’t know. Anyways, I’m moving on. So let’s clear our screen and create our first directory. The command will be MK, D I R or MK for make directory. D I R that’s how I remember space. And then the name of your directory. It’s that simple. We’ll call this cool stuff and that’s it. If I type in LS, dash L cool stuff is right there. Now what I want you to notice is that first of all, the colors are different. Now I have no idea what color that is cuz I am colorblind. And honestly, when I’m dealing with tech, I don’t rely on colors because I am colorblind. I hate colors. 

So normally I rely on other stuff like the data over here. So you may be able to tell, and I can kind of tell that cool stuff is a different color than like cat, cat dot TXT. That means that cool stuff is different. It’s a directory versus cat cat, which is a file. But for me, a better way to see that and probably a cooler way to see it is over here in the file info. You see that first letter right there. That first letter tells us if it’s a directory or a file D directory, easy enough. Right? And then over here, like that file can’t it’s just a dash. That’s how we know it’s a file. Colors can trick you trust me. But over here, this won’t trick. You it’ll tell you exactly what’s going on now. What’s cool about the make directory commander, M K D I R is you can make multiple directories, kinda like touch with one command. 

I can go. This is a directory. Actually, all of these are. And each of these individual words will be a directory except for this cuz that was already a file. Everything else will be though. If I type in LS, dash L it created a bunch of random directories. So now let’s give these directories a purpose. The purpose is to hold stuff, files, let’s move some files inside of these directories. So our task right now, let’s focus on the cool stuff directories. Cause that’s where I wanna put cool stuff. We’re gonna move all these dumb files we created inside the cool stuff, directory. So I clear my screen. The command will be M V for move. That’s it? That’s simple two letters. I love it. And with this command, the first thing we’ll do is specify the file. We’re going to move and I forgot them already. 

So I’m gonna type in SL or SL LS L see what we’re working with here. Cool. We’ll move. File dot TXT first. Okay. So MV file dot TXT, and then we’ll tell it where to go. Now this is gonna be kinda weird if I wanna type in this period slash and then the directory name, cool stuff. Now, why did I put in period forward slash and Linux? When we put in a period, we’re saying, Hey right here, that’s where that folder is. Cool stuff is right here. And that’s where the cool stuff folder is. It is right here where we are in our current working directory. It’s in our Tilda, our home directory. If we didn’t put that period, here’s what would happen. Let’s take it out it enter. And it’s gonna go, yo, first of all, permission denied. And second it’s not even there. 

What we’re actually saying. And we’re lying is that we’re saying that cool stuff lives at the root of the file systems. You know, we type in slash to get to the root of the file system. Like watch, we can do it right now. CD slash we’re not the root by type in LS, all the root stuff. We saw that in our video where we talked about the Lenox file system in 1,233 seconds. Was that, was that what it was? I think it was, I noticed there is not a folder called cool stuff here, but we were lying to it. That’s why we have to do the period to say, dude right here. So if you user up arrow a few times, make sure our period is there before the forward slash head enter. Oh wait, I forgot to go back home CD. That’s it go back home. 

Bend, run my command once more. Now I can move it. Cuz cool. Stuff’s right here. Head enter. There we go. I just moved the file out. TXT into the cool stuff. Directory. If I type in LS, dash L filed out TXT, he’s gone, man. He disappeared. He now lives in here and we can find out real quick. We can type in LS from here type in LS and specify the directory you wanna look inside so I can say LS, cool stuff. I wanna look inside. Cool stuff. There he is. File out TXT. We moved him. He’s home safe. He talked to men coffee break. Let’s try moving. One more thing. So we’ll do envy. Let’s this time let’s move, um, stuff TXT. So move stuff. Dot TXT. We’ll move it into the cool stuff. Directory period. Four slash cool stuff. But this time we’re gonna put in the witness protection program. 

<laugh> we’re gonna change his name in the new directory. Can we do that? Yeah, we can just right after cool stuff type in a new name, new identity dot TXT head enter. And not only did we move him. Cause if we do, um, LS, dash L CF stuff, TXT is there anymore. He’s not, he’s not there, but if we LS cool stuff that he, or just cool stuff, the directory there he is with this new identity so we can move stuff and rename it at the same time. Kind of cool. We can also move a lot of things all at once. So for example, I wanna move this dot TXT and touch to the cool stuff. Directory. I specified multiple files right after I move. Then the location I wanna move ’em to done. They’re all moved. Now. If I LS cool stuff, bam, they’re all there hanging out. 

Now. Sometimes we may not wanna move things. We wanna keep it where it is, but we want to copy it somewhere else. And we can do this for a lot of reasons. One of the main ones is you wanna back up a file before you change something. So let’s try it out real quick. Clear our screen. Actually I wanna do LS L what my files are. I wanna back up, can’t touch this dot TXT. I’m gonna copy it. So to do that, I’ll use a new command C P for copy. Then just like the move command. I’ll specify the file. I wanna copy over this will be can’t touch this dot XT and then I’ll specify the location. I wanna move it to so I’ll move this guy over into cool stuff. Now this will operate very similarly to the move command. I can move it over, just like that or not move it. 

Copy it over now by LS dash L. I can see that can’t touch. This is still where we are. It still exists there. But now by LS cool stuff, he also exists there. That’s super handy and just like move. I can copy him over and give him a new identity. I’ll name him. You can touch this. That’s XT backed up new identity by LS, cool stuff. There he is. And of course often you might wanna just back up the file and the same directory you’re in. So right now the hip PWD I’m in the home, our home directory home suite Tilda. I can do copy. Can’t touch this and then just specify another file name. Say, can’t touch this. This is what people normally do. Dot tht dot BK for backup. Bam. So now I do LS dash L I’ve copied him over to a backup file. 

Keeping in mind does have to be a different name. You can’t have the, the same file name and the same directory just doesn’t work out. Now what I want you to do real quick and I’ll do it with you is if you have any extra files, just hanging around some loose hangnails. I want you to move those suckers, move them, not copy ’em into the cool steps directory. We gotta clean this place up. So I’ll do it real quick. And V I’ll do can’t. You can’t touch this and all the rest of the files. I think that’s all of them. I’ll move them over. LS dash L to make sure it’s all done. Oh, forgot one. Forgot. Yes. Taking you out. Yes, there he’s gone. We got it. Now getting back to directories, I’ll show you the beginning. Part of how I created over a million directories here in Lenox. 

Um, I use the MK D IR command, MK DIR, but there’s a switch that’s really, really handy. Dash P with this. We can create directories and also child directories underneath. So we’re actually creating a parent directory with child directories. That’s what P stands for dash parent. I’m a dash parent. Are you a dash parent? So this could be like directory slash another one for slash another one for slash another one head enter. And I just created a lot of directories <laugh> so if I do LS L all we’re gonna see right here so far is directory. But if I do this, and this is actually a new command at really, really fun, cool command, it’s fun. <laugh> so I’m gonna type in tree, just tree type in tree, hit enter, and it gives us a really cool view tree, if you will. <laugh> of our current working directory. 

And if I scroll up a little bit, just to the middle here I can see right here is where I created my directory directory, and then all the other directories inside another one, another one, another one. So I pretty much spamed that, uh, command to do something crazy. You’ll see it here in a bit. You can even try it. If you want, I’ll show you a couple more things, then we’ll jump right to destroying the box. Um, actually we’re gonna destroy it twice. I’ll show you. So let’s like clear our screen real quick, a few more things with directories. If I type LS dash L, I can see that I have, I’ve got cool stuff. What I wanna do is move cool stuff. Yeah. We’re gonna move a directory. I wanna move it inside of directory. And actually I wanna put that inside of another one. 

Let’s do it. Let’s knock it out. It’s actually the same as moving a file. <laugh> just type an MV for move. We’ll specify our directory cool stuff, and I’ll move it to period. Four slash directory. Another one. That’s it hit enter. It’s done. So if I do LS dash L cool stuff is no longer here, but if I type in tree and scroll up a bit, our tree has some new, I think you call it leaves. Yes. Leaves another one right here has another directory inside of it with all these files. So you can move the directories. That’s cool. And you can also copy directories. Let’s copy. Cool stuff into, uh, <laugh> the another one below him. If you’re <laugh>, if you’re, um, if you’re lost, you’re not alone. So I wanna change my move to copy CP. Now, wanna type all this in. Hopefully I get it right. 

There we go. Yeah. Another one, another one copying. Cool stuff. Go. And something interesting happened here. Glad it happened. Notice it’s like, Hey, um, you don’t use dash R what does that mean? Well, see that directory we have here. It has stuff in it. And if we’re gonna copy stuff over, it wants us to use the dash R command, which stands for recursive. I’m not gonna define that. Go look it up, essentially. What it means for our situation here is, Hey, let’s copy all the files inside of it too. So I’m gonna run that same command again. So let’s bring it back up here. I’ll do control a to get back to the beginning of my command and I’ll do CP dash R hit. And it actually worked no errors this time. If LS the <laugh> another one, another one directory, cool stuff is in there. 

And if I LS cool stuff inside of there, this is like getting inception, inception, inception. We’re like in a dream and a dream and a dream there. They all are <laugh>. So if you’re following, that’s what happened and let’s get a tree of you. So we’re not totally lost. Yep. There’s all that we did. Cool stuff. Cool stuff exist. We copied it over to a child directory. Now we’ve had so much fun creating things. What do you say? We destroy? I say we should do that. Let’s remove some files. How do we delete stuff? That’s the fun part, right? So let’s clear our screen and let’s create a quick file just where we are. We’re in the home directory, home suite Tilda, and I’ll do touch, please. Don’t delete me. Ma’am so if I do LS dash L, there he is right there. How do we delete that file? Like all things in this video so far, it’s very, very simple. It’s just knowing the command. The command will be R M for remove RM. And then the file you want to delete. The file is please don’t delete me. We’re gonna ignore his final plea. Nora has final plea. Take him out. And if I do LS dash L he’s gone and just like copy and move. We can do multiple things at once. So I’ll create some more files. 

Please don’t delete me. And then I’ll delete them. Remove, please don’t delete me just like that. We can also remove directories. And this is where things get kind of fun. Now let’s say we wanna derate delete the directory. Actually. Here’s how we’ll do it. The command will be RM. And then D I R for remove directory, we’ll then type in actually to specify our directory. And that’s it enter done. If I type in LS, dash L actually is gone. He’s actually gone. But here’s the, the kicker here. Watch this. If I type in RM D R for remove directory, and let’s say we remove the one we work so hard on, but we don’t care anymore. The directory directory that has all the other ones and all of our cool stuff backed up in, let’s try to remove him. So RM D I R specified directory. 

Isn’t gonna work. Watch, whoa, fail to remove. It’s not empty there’s stuff in there. And you’re thinking to yourself, well, I knew that, but you may not have known that Lennox is trying to protect you from yourself. Both tell ’em we don’t need it. Take our gloves off and get a little crazy, the best way to remove a directory that has stuff in it is to not to use the remove directory command, which is very confusing. You wanna use the, just the RM command remove. So RM just like this and this time we’re gonna use a new switch, actually, a switch we just used earlier. Dash R. It stands for the same thing. Recursive where before we recursively copied everything inside a folder to another destination this time we’re gonna recursively remove everything inside of a folder. Along with this directory, we’re just gonna obliterate it. 

We’re gonna take out directory. This is not reversible. We’re just gonna do it. So RM dash R directory, say goodbye. We’re taking out all that hard work we did done <laugh>. So if I do LS dash L, it’s gone. If I do my tree command, we just pruned our tree. It’s gone. Everything’s gone. Now, can I show you something dangerous? I probably shouldn’t show this to you. I wanna do it anyway. Okay. If you’ve been watching my channel for a bit, you’ve already seen this. Um, but this command will scare you. The can command will be RM dash R and we’re also gonna throw in an F what does that mean? Well, let’s actually look it up. Let’s do RM dash dash help. It’ll tell us all the switches we can use and how much film we can have with it. We can see that R means what we already knew. 

Recursive remove directories and their contents recursively. Also dash F means we’re gonna be a bit forceful. And what that means is we’re gonna ignore all warnings. Linux is gonna tell us, Hey, you probably shouldn’t do that. Hey, stop warning, sign, warning, sign. We’re gonna go, Nope, gas, the pedal going right through it all. That’s what force means. <laugh> so we’re gonna do that. We’re also gonna use, and I haven’t showed this to you yet. We’re gonna use dash dash no preserve route, because we’re gonna, we’re going, we’re gonna try and delete everything and we don’t want it to be, uh, want it to have special treatment. And that’s what this is doing. So let’s get back to our command line. We’re gonna do RM dash RF. We do dash, no preserve route. And then we’ll do board slash what we’re saying here is, Hey, I want you to delete everything. 

Recursively, starting at the root of the file system that will break everything. It will a hundred percent. And also just to add a little bit of spice to it, control a, go to the beginning of our command to type in pseudo. Let’s give it pseudo permissions. Let’s give it rights to do this. Now, before you stink and do this, make sure it’s on a machine that is, um, ephemeral temporary, like this hack the box machine also, before you do it, uh, if you’re on the free version, if you’re not paying for hack the box academy, you only get like one instance per day. So if you run this right now, it’s gonna break. And, uh, you won’t get to reset it for me. I can reset it and run it as many times as I want. Cause I pay for it. So anyways, don’t do this until you’re like done for the day. 

And also don’t ever do this on any other computer, unless it’s temporary or ephemeral. Did I say that already? I just wanna make sure you got that. Anyways, here we go. Running this command. So it tell me a lot of things that can’t remove, but it also already removed a lot of other things. So if like, for example, if I bring up another command prompt, if it’ll even do it, it won’t control. See this. If I try to do anything like, um, PWD gone doesn’t work, um, echo high, remember everything in Lenux is a file. And we just deleted a lot of files. So those files were our commands. Those files were things, how we did things. So that’s how you can break Linux. That was fun. I’m gonna reset my Linux now. Okay. Machine is back up here. We go tend to create a million directories. 

I’m gonna lost my terminal. Now I, as I said before, I’m gonna use the MK D IR command with the dash P switch, create a bunch of parent directories or child directories. Actually, first I’m gonna do an LS dash L show you what I got here. Just four simple directories, nothing going on. If I type in tree, very simple tree, a few files in there, no big deal. And here’s what I’m gonna do. I’m doing that. That’s simple because the dash P command allows me to nest a lot of directories within a directory. Uh, now I’m not gonna do this specifically because there is a limit on the number of child directories. I’m not sure what the hard limit is. I’m not sure if it’s this machine or whatever, but I can only create about 600 or so in one go. So parent directory with like 600. 

So child directories. So what I did using some bash scripting skills, I created a script that will create more parent directories with 600 in those, and just did it over and over and over again, like 1500 times. You wanna see it? I’ll use nano another one. Do H I’ll do control shift V to paste it all in there. Just a simple for loop to do something crazy. It’s gonna take a bit control X, Y enter a stave and time to run the script dash another one do H here we go. Okay. That took a minute, but I think it’s done. So now let’s type in tree to see what we’re dealing with here. <laugh> watch this. <laugh> I feel like I’m falling down like a, a forest, or like going through a forest, hitting in the, in the face with trees, branches and stuff. You know what I mean? I feel like this should be like a screen saver. Just break it. There it goes. That’s gonna do this for a minute. Okay. It’s finally done. And there’s our number 1,116,017 directories, which is just, I don’t know. <laugh> because this girl threw this. It’s so stupid. This was stupid. I know, but I did it like a million directories named another one. Oh, by the way, have you hacked the YouTube algorithm today? Just make sure you do hit that light button notification, but comment. Subscribe. We gotta hack YouTube today. Ethically. Of course. Yeah. That’s all I got. I’ll catch you guys next time.

Check Out Network Chuck's Coffee and MERCH Shop