All right.
So now that you know how to make files and directories using the touch and mkdir air commands, let's
take it up a notch and mess around a bit.
So let's say that you're working on a big five year project and every month because the admin staff
hate you, you need to write 100 memo files to keep track of the project and the folder should be named
something like Jan 2017 Feb 2017 Mar 20 Mar 2017 and so on and so on for five years.
And in each of these folders there should be 100 files, far one file two fall three all the way until
file 100.
How can you create those files and folders up front?
Well, doing it graphically would be horrific.
There's actually just no way around it.
There will be a whole lot of copying and pasting and a whole lot of renaming.
And you're right click finger would be basically in agony by the end of the whole ordeal.
But let me show you how easy it is to do on the command line.
So to make this possible, we're going to use a powerful feature of the shell known as brace expansion.
And this is totally awesome.
Check this out.
So let's go ahead and open our terminal using our control alternate keyboard shortcut.
And then what we're going to do is we're going to head over to the desktop using our command, and we're
going to make a big folder called Project and there we are.
It has appeared now in here.
This is let's go change into it, change into that project folder.
We can see that now we're in the project folder on the desktop and this is where the magic happens.
We need to make 60 folders, right?
And they should all be in the format.
Jan 2017 Feb 2017 Mar 2017.
Okay, so like three three letters then 2017 all the way up until December 20, 22, so Dec 2022, which
is when the project ends.
So what if I told you we could make all of those folders in one line?
This is all possible using the power of brace expansion.
So here comes the command.
And what I'm going to do is I'm actually going to maximize the screen because it's kind of a big one.
What we're going to do is we're going to type mkdir, then we're going to open up a pair of braces and
the braces are these squiggly brackets here and then we're going to type without any spaces.
Jan Comma, February, comma, March, comma, April, May, June, July, August, September, October,
November, December without any spaces at all.
Okay, then I'm going to type in underscore.
Then we're going to open up open up another pair of braces.
Okay, then 2017, 2018, 20, 19, 20, 20, 20, 21 and 20, 22.
Whew.
So that's quite a long command, right?
But what's happening here is something called brace expansion.
And here we have some braces, so we've got one set here and another set here for the for the years.
And the way that the shell is going to expand these braces is similar to how you would expand brackets
in algebra class.
Okay.
So what happened first is you get January 2017, then February 2017, then March 2017 and so on and
so on until you get December 2017, then it'll just start all over again.
You'll get January 2018, February 2018, then March, April, May, June, July, all the way until
you get December 2018 and so on and so on, until you get all the way until December 20, 22.
Okay, so enough, enough suspense.
Let's go ahead and press enter.
Let's go ahead and run that.
Now, let's see if it works.
So we're going to go into our project folder.
Oh, my goodness.
Look how amazing that is.
Right.
So we've managed to create folders in that wonderful format there for every single one of the years.
And if we highlight them, it tells us that the 72 folders are actually created.
So from January 2017, right here, all the way until December 2022, which is right there and everything
in between, isn't that awesome?
Just just as an aside as well, if I just maximize this here to save us a bit of typing, we could have
actually, instead of typing out each of the dates because it's just numbers.
They're just numbers, right.
That are in a, in a constant pattern.
We could have just done dot dot.
So 2017 to 2022.
So that's another aside right there.
Now imagine how long it would have taken to do that stuff.
Using point and click methods.
Can imagine how annoying that would have been.
Well, we just did it in one command line.
Okay.
So now that we're sitting here feeling very smug that our command line has just created like a bajillion
folders all in one go, we've still got a little bit to do, and that is we've got to create 100 files
in each of these folders.
Now, how are we going to do that?
Well, actually, it's quite easy.
We'll just use base expansion again.
So what we're going to do is we're going to open up our terminal again, go onto the desktop, go into
the project folder.
Okay.
Now in here, I'm actually going to maximize the screen.
Watch what just watch what I do and then we'll see how it works.
Okay.
So we're going to type touch, then I'm going to open up the braces.
Jan February, March, April, May, June, July, August, September, October, November, December.
Our underscore and our our years.
So 2017, 2022.
Oh, by the way, it doesn't just have to be numbers, it could be A to Z or A to Z or something like
B to F or something like that.
So anything that is, that has a pattern like the alphabet or numbers, and you can use the dot dot
thing to make that happen.
But we're after 2017 till 2022 now inside each of those folders, we're now going to make a file call
that starts with file, and then the number is 1 to 100.
So what is going on here?
This is mad.
Ziad, where where has this command come from?
Well, basically what I'm saying is for each of these folders from January 2017, all the way until
December 2022, in each of those, make file 1 to 100.
Now, this is just a bit of fun.
Okay, so don't worry if it seems a bit like what?
It's just to show you how powerful the shell can be.
Let's take a look at it.
So let's run that and let's close the terminal again.
Let's go ahead and take a look.
Let's open up June 2022, because that's that's a good date.
So if we open up June 2022, we click that.
Oh, my goodness, we've got file one, two, 100.
Okay, maybe that was just a fluke.
What if we open up December 2020?
Nope.
This file 1 to 100 in there as well.
What if we open up January or let's say April 2020?
There we go again.
We've got far 1 to 100.
So isn't that awesome?
Guys like you can see the way that we've just used brace expansion to make our terminal command unbelievably
powerful.
And if we've got 72 folders, I said we were only going to do it for five years.
We ended up doing it for six.
But if we have now got a 72 folders with 100 files in it each, we've just used one command line to
create about 7200 files in one go.
Now, I hope you can see just how powerful the shell is from from that little example right there.
And by the way, brace expansion isn't only possible for the touch and mkdir commands, by the way,
it's actually usable across the whole shell.
So, for example, let's take the LZ command, let's take the LZ command.
We can look in every single folder and get a list of what's in there.
So if I do Jan, February, March, April, May, June, July, August, September, October, November,
December, and then 2017 till 2022.
Okay, so I'm saying list out the contents of every single one of these folders basically.
And I press enter, oops, I'm in the wrong place.
So I'll go to desktop slash project now press up key twice to get back there.
Go again where we now can see the contents of every single one of the folders and you can see they all
have 100 files in it.
And we can see here that we get the files 1 to 100 and every folder and it might look like the file
ends in file 99.
But what's actually happening is if you look over here near file, what it's doing is it's sorting them
alphabetically or sorting them numerically here.
So you see file one, file ten, file 100 because they all start with one, right?
And then the nines end up over there.
But no, we are getting files, 1 to 100 in each.
And let's let's say that we wanted to take all of this output, right?
This massive output that we just got and redirect it, redirect all that output into a file called output
txt.
And now when we, when we take a look, we've now got a file called txt and if when we take a look in
there, we can see that we've got all of that content in there.
So April 2017, it tells us the files that that has and then it tells us what's in April 2018 and it
tells the files in there and this is all alphabetically sorted in there.
Isn't that awesome?
I'm just showing you here.
We now have an epic file with the contents of 72 folders and in about 7200 files in just one command
line.
Tell me that isn't epic and would have took you forever to do using point and.
Like methods now I appreciate this is really is this bit is really going to be a bit like whoa and that's
okay all right.
I'm just showing you these basic skills have these basic skills such as creating one file or creating
one folder can easily be turbocharged with very little effort, as long as you understand a little bit
about brace expansion and wildcards.
But I'll leave the imagination as to why why you would do so up to you.
Because these skills can be applied to many different things.
And, you know, just just to just to show a much simpler case of brace expansion.
If we go to the desktop right here and let's say we just want to instead of saying touch, file a,
text, file B txt and file c txt which will work fine, we'll create three files and brace expansion
just makes that a bit easier by saying file.
You give it some brackets a, b, c, txt.
So you can say we're using the the bracket, the braces here because it's going to go file a text file
b txt file XD a press enter.
Now we are we've used brace expansion to expand that out.
So brace expansion comes into play all over the place.
And because here we are, we've got some text which is a follows a very simple pattern.
We can use the dot dot here and we're going to get the same result.
We could we could maybe say, okay, I want file F all the way to V.
Now we are going to get file V all the way to F on the desktop as well.
So here we are here as F and there's V.
So just showing you that's brace expansion.
It's not particularly complicated thing.
Trust me, there are useful things for what I'm showing you here, but I just wanted to show you just
how powerful the shell can be with just a little bit of tweaking.
So that's enough of command line craziness for now.
Let's just have a quick recap of what was actually important from the last two videos.
So first of all, you saw how to use the touch command to create new files and the use also saw how
to use the mkdir command to create new directories, which is my favorite way of saying the command
by the way.
And you also saw that the mkdir command also has a powerful p option that can be used to create entire
folder paths.
So this is creating one folder inside of another folder inside of another folder, all from scratch,
which is very, very powerful stuff.
You learn that creating folder files and folders in Linux is case sensitive, and you learn that it's
kind of a bad idea to have spaces in your file names.
So use underscores instead.
And finally we took file and folder creation to the next level by using brace expansion and embrace.
Expansion is kind of an advanced technique.
So don't worry if you didn't understand it, it's not technically part of the course, but you got to
see it here anyway.
So lucky you.
But now that we've got a whole bunch of files and folders cluttering up our computer in the next video,
you're going to learn how to remove them.
So to learn how to delete files and folders, I'll see you in the next video.