All right.
So in this lesson, I want to introduce you to directory creation,
file creation, and directory manipulation.
And we're going to be doing all of this
inside the command line, just with our keyboards.
Now I'm starting in my root directory over here.
And I am going to create a New Folder right here.
Obviously, I can go through the right-click, New Folder, all of that,
but we are pro-developers now, so we're going to get used to using the Command Line.
So the command is "mkdir" or make directory and then we're going to give our directory a name.
So let's just call it Angela, right?
And you can see, there you go, pops up a new folder called Angela.
Now let's cd into this new directory and you can see that if I click on here or if I use ls that there's
absolutely nothing in there.
It's an empty folder.
So what if I wanted to create a file in our Graphical User Interface?
I could say open up an application like TextEdit, and I could make a file and write something in it and
then save it inside my new directory.
Do a little bit of navigating in order to get there, and then I have to give my file a name.
Let's call it Text and hit Save.
Now we have to exit the application.
And after all of that work, I've got a text file.
And if we do ls now, you can see that Text.rtf exists.
But if you want to do the same thing using the command line, then it's as simple as simply typing "touch"
to create a new file.
And then we're going to specify the name of the file,
let's call it Text2 and then we give it an extension .txt. And you can open it either by double-
clicking on it, which is what we're used to, or you can simply write, open Text2.txt
and it will open it using the default application which is TextEdit in a Mac.
Now you can specify which application you want to open this file in and all you have to do is say Open,
and then you're going to use the -a flag,
then you're going to specify the application that you want to use.
And then I can specify the file that I want to open,
so Text2.txt and hit Enter and it will open up the application that I've got and then open up my
file for me to be able to edit.
So what if you wanted to delete files inside the command line?
Currently, I'm inside the Angela folder and there are two files and I want to delete my Text.rtf.
Then all you need to do is just use the 'rm" command which removes files.
If you type the command as is,
so just rm, and then we're going to specify Text.rtf to remove.
And once I hit Enter you'll see it disappear,
also in the Finder as well.
Now what if I want to remove all the files inside a folder?
So let's create some more text files.
So let's call it Text.txt and then let's create Text3.txt.
So now I've got Text,
Text2, Text3.
A little bit of a tongue twister there. And I want to remove all of them.
To do that, you have to be inside the directory that you want to remove all the files from.
And if you want to know which directory you're currently in, you can either look at the part that's
before your username and prompt.
So, in this case, I'm inside a folder called Angela, but you can also use the pwd or Print working directory
command, and then when you hit Enter it tells you your entire path and your current folder location.
And now I want to remove all of them in one go without having to type, rm Text.txt, etcetera.
Again, we're using the remove (rm) command and then we're simply going to use the asterisks (*) as a wildcard
which matches everything that has every single name.
And now if I hit Enter, you can see that all my three files inside my current directory are removed.
So do you remember in the beginning of this module we mentioned that using the command line gives you
more power, more control, and as we all know, with great power comes great responsibility.
And that means that you have to be careful when using certain commands because the Graphical User Interface
isn't there to protect you.
So, for example, if you were not inside the directory that you wanted to delete, say if you were
inside your root directory and you, you know, tried to remove all the files inside your root directory,
then it's probably not such a great idea.
So always check which location you're in before you're doing some of these destructive commands.
Now to remove folders or remove directories, there's a different command.
So now I want to remove this Angela folder that I've created and I'm inside the right place to do it.
I'm inside my root directory, which is at this level.
And again, always check where you are by using the ls command.
You can see that I am at this level.
So now I want to remove this Angela directory and if I just simply write, rm Angela and I hit Enter,
you can see it says that, " 'Angela/': is a directory".
So this rm command by itself is not going to work. To do it,
we actually have to add a flag which is the -r flag.
So this allows you to remove a directory.
So now let's try that again.
rm -r and then we're going to use the Angela directory
and if we watch over here and I hit Enter, you can see that that directory is now gone, including
all the files that it held, all the folders that are inside the Angela folder and it removes all of
its child components.
Again, these are destructive commands,
be really careful when you're using them,
and in fact, there's a pretty hilarious bit of Internet history, which is where somebody submitted
a question to StackExchange serverfault, which is similar to Stack Overflow, but it's more for sys admins
and network admins.
So what he said was "Monday morning mistake," he used the sudo command which stands for Superuserdo,
which uses your admin privileges to basically allow you to do things that are probably a little bit
dangerous.
And he used the rm command and then the -rf flag.
So we've already seen the -r which allows you to remove entire directories and all the folders and
all the child folders it contains.
He also used the f flag, which stands for force.
So this doesn't ask you for a confirmation.
And then the very last thing, which is something that you should probably never, ever write
and there's very few cases where this is actually useful, which is the "no-preserve-root/".
And what that means is that along with everything else inside this command, it basically wipes your
hard disk to the point where you cannot recover it.
And this guy said, "Monday morning, mistake.
I basically just wiped my entire server," which obviously contains data from other people who are using
his server," and what do I do?"
So as it turns out, this is actually a hoax where this guy is trying to advertise his server company.
And I mean, it's clever or is it not clever?
I'm not sure that it's positive PR, but it got a lot of attention on the Internet.
So if you're interested, you can have a read of this and I'll link to it in this lesson.
But basically, if you have a look at the answers, you can see that this is something really bad to
never do.
So with great power comes great responsibility.
And in this module, I've introduced you to some of the most common commands that you're going to be finding
yourself using and also some of the most common shortcuts.
And if you want to learn more about the command line, then this is a website that I highly recommend.
I have nothing to do with them,
it's just something that I found to be written quite well.
So it's completely free and it's called the Command Line Tutorial.
Learn Enough Command Line to Be Dangerous. Again, the title is repeating what we just said before,
but it goes into more depth like grepping, curl, all of those things that you might have come across
and you will certainly come across more of it in your journey as a developer.