Hello there.
You're beautiful people.
And in this video, the time has come.
Over the last few videos you've been learning about the structure of the Linux file system.
You've been learning how to navigate the Linux file system using the command line.
You've been learning about file extensions in Linux and how they differ from what you might find on
other operating systems.
And in the last video you've learned about wild cards and how you can use them to turbocharge your workings
with the command line.
But in this video, you're going to take your first step from just looking at the Linux file system
to actually modifying it by learning how to create files and directories using the command line.
And in this video you're going to learn how to use the touch and the mkdir commands to create files
and directories and by the end of this video you're going to be able to create your own files and folders
using the command line.
And then in the video after, we're going to show you how to take what you learn here and turbocharge
it by combining it with wild card so you can create like a bajillion files and folders in just one command.
And that's not even an exaggeration.
Let's go ahead and jump right into it.
Okay.
So the first command we want to take a look at is something called the touch command.
And the touch command can create new empty files.
So let's say that I want to create a new file called File one on our desktop.
So if I just head over to the desktop and I try to create a file called File one, all we have to do
is type touch, file one.
And we can see here that file one has been created and it appeared.
It's pretty awesome.
Now you don't have to do this in the directory that you're in, by the way.
So for example, if I did something like Touch and then said, I want to put that in the documents folder
and make another file called Distant File inside the documents folder.
Now, when I go ahead and take a look inside the inside the documents folder, we can see that distant
file has been created and remember that these files here are all completely empty.
They just blank files when you use them, when you create them using the touch command.
So that's pretty cool.
Right now, the files that we create with the touch command are completely empty, as I said.
But if we want to create files that actually have some content in them, that's where we can use the
Echo Command to redirect content into it.
So I'm on the desktop if I want to use the echo command to make a file called hello txt and want to
put the content the just the text.
Hello in there.
Then I'll just type hello and redirect that into hello text.
Now redirection.
When you redirect to a file that isn't made yet, the shell will automatically create that file and
put what.
Put what was going to go inside there inside it.
So if I go echo hello and then redirect that to hello text the show will create the file and when we
open it we'll see that hello is inside that file.
So that's another way of creating files.
Okay.
So that's how you use the touch command to create files.
Let's see how you might go around creating folders, making directories.
So the way you make directories in the shell, if I just clear the screen, is with the MK Command,
which stands for make directory.
So make folder and it works basically the same as the touch command.
So if we try to make a folder on our desktop called folder, then all I'd have to do is type mkdir and
call it folder press enter.
And we see that a new folder called folder has appeared pretty cool, right?
Again, this can happen at a distance.
It doesn't have to be in your current working directory.
So if I wanted to make a folder in our pictures directory called Holiday and I press enter, then I
can check that in two ways.
I could press CD to go back to our home directory, go into pictures using CD, and when we take a look,
we'll see that the holiday folder is there.
We can have a look in our graphical user interface as well.
We go pictures and we've got a folder called Holiday that exists right there as well.
Pretty cool, right?
Now you can.
Instead of creating folders one at a time, you can actually create entire folder paths all in one go.
So I'm back on the desktop and let's say I wanted to create this path, I wanted to create blah, slash
thing, slash blah, but I can't go ahead and make that in one go because the show is going to give
us an error and it's going to say that the blah folder doesn't exist.
This is because the shell tried to go to blah then to thing and then create qibla.
Now that's just the most ridiculous sentence in the course so far, don't you think?
Anyway, if we tried to give the mkdir command the p option so we do mkdir the p give it the p option.
It will then create the entire path even though none of the folders exists.
So if we do blah slash thing, slash blam and type it like that and press enter, we'll see that.
Now we've got blah and inside there we've got thing and inside there we've got a problem.
So that's really cool.
We made the entire path all in one go.
How awesome is that?
Right now there's something to bear in mind when creating new files or directories, and that is to
try and avoid putting spaces in the name.
So for example, if I create a folder called Happy Birthday, if I type, if I type mkdir happy birthday,
you see that?
What actually happened is we created two files, a two folder, sorry, happy and birthday.
And that's because there was this space in between the text and that basically made it two command line
arguments.
We gave it one input which was happy and one input which was birthday, but we wanted to be just one
input.
Happy birthday, just one input.
So how do we do that?
Well, actually, the way you do that is you do mkdir, then surround it in quotes happy birthday.
And when you do that, you see we get one folder called Happy Birthday.
But just in general, having folders with our files with spaces in them is just a bit of a nightmare
in Linux because of this whole space issue in the command line argument and all that stuff.
Okay.
So usually what you want to do is instead of having spaces have underscores instead.
So instead of having Happy Space Birthday, usually what you want to do is have underscores instead
underscores being this little, little symbol here.
So here you can see that we have another folder but with an underscore instead of a space and that just
makes it work a lot nicer with tab, auto completion and just loads of other stuff like that.
It stops you messing up your command line arguments and things like that.
Another thing, of course, I think I've mentioned this multiple times, but folders and file names
are case sensitive in Linux.
So if I do mkdir happy underscore birthday, that's a completely different folder to happy birthday
in lowercase, whereas on something like windows it actually wouldn't be okay.
So that's a quick overview of how to create files and folders using the touch and mkdir commands in
the next video.
I'm just going to break it here.
In the next video, we're going to take it up a notch and start combining all this goodness with wild
cards and a really powerful ability called brace expansion, which is going to allow us to create hundreds
of files and folders all in one command.
So let's go ahead and cut it right here and I'll see you in the next video.