Transcripts
1. Introduction: There was a time when
I needed to create a specific structure of folders
for different projects. So in the beginning, I
was either creating this every time manually from
scratch, or later on, when I noticed that what I was doing was simply
a waste of time, I would usually keep a directory like a template and
copy data wrong. Today, I know there's a
better way to do this, and this is by
using the terminal. Yes, that's scary
thing the terminal. So if you are a
Macues or Linux user, I'll show you in just a few
minutes how you can become a power user and
create 100 folders, each containing
four other folders with just one
command. Let's begin.
2. Opening a terminal window: Let's begin with something
you may already know. There are at least two ways
to interact with a computer. One is by using a
graphical user interface. This is what we usually do
every day, for example, when we're opening
Finder or just navigating through the files and folders that we
have on our computer. And the second option is by using a command
line interface, also known as CLI to send
commands in a text form. Graphical user interfaces are
a relatively new invention, even if they were there since you started using computers. So it's no wonder that all these operating
systems, including MacOS, which is based on
Unix and Linux, can be fully controlled
just by using commands. And quite often, these
commands allow you to do things that a graphical user
interface won't let you. So for power users, they are so much more effective and they are
not complicated at all. To run commands, you need
to open a terminal window. So what you see right
now on the screen, this is a terminal window. In your case, it may
look a bit different. On Macust, you can
search for terminal, so you can press Command Space and start typing here terminal. So this will open up
a terminal window. I'm actually using term two, which is an improved terminal. But what I'm going
to show you here is going to work
absolutely the same. And if you're on
Linux, all you need to do is open the terminal. This is typically
available from the menus. So once you open up a terminal, what you're going to see here is a prompt. So this is a prompt. This is where the terminal is waiting for you to input an instruction to
input a command. And you need to be very careful how you
write this command. So always try to replicate exactly what I'm
showing on the screen, adding an additional
character or space can totally change what
the command does, or it may not even work. So, for example, we can
try out the command, who am I and this needs to
be written in one word. You're going to see
here on the next line, it's going to tell
my current user. We can also use the command PWD, and this will tell us exactly where in the file system we are. So I'm currently inside the user's directory inside the directory called Valentin. So this is the current
path where I am. And additially we can also
use a command like echo, which prints out a message. So if we type here, hello, we're going to get back Hello. Very simple. But if you type something
that doesn't exist, for example, we
type the command, hello we're going to get back here an error saying
command not found. So whenever you're getting
command not found, check again if you have input
it the correct command.
3. Creating a folder using the terminal: So let's go ahead and continue by learning about
a useful command, a command that will help
us create a folder. But first of all, let's go
ahead and clear the screen. So if you're not happy with what you're seeing right
now on the screen, you can simply press Control L, and this will clear your screen so you can
have a fresh start. Okay, so how do we
create a folder? We're going to use a command
which is called K DR. So this stands from
make directory, and it's actually just
easier to see make directory because
technically speaking, in the Linux Unix world, a folder is called a directory. So this is what it is. But we're going to use
simply the term folder because most likely it's the
term that you're used to. Okay, so what we need to do here is to create a directory, and we're going to create
a directory called Test. So this would be the name of that directory. You're
going to press Enter. This directory is
going to be created in the current
folder where we are. So where we are is given
by the PWD command. So inside users Valentine, I've created a new folder. Just as well, we create a
structure of different folders. For example, we can
have a folder and a subfolder and
another subfolder. Again, this can be done
with the same command, so we can write here
something like test two. I'm also going to
be very careful not to include any spaces in the names of the directories because spaces are a
bit more problematic. And then if I want to
create a subdirectory, all I have to do is put
at end of forward slash. So I'm going to say
here subdar one. Forward slash sear two. So we're going to have
a folder here with a subfolder and
another subfolder. I press here, Enter, and what we're going to
get here is initially an error because by default, this command, make directory you cannot create this structure. But using the upper
key on the keyboard, I'm going to bring back
the previous command so that we can edit. I'm going to go here
right at the beginning, and I'm going to add
another modifier, something that changes
a bit of behavior. It's called a flag right here P, to make sure that there are
a space before and after. We don't need this
extra space here. And what will this do is to
create this nested structure, which we can also inspect. Now quite often,
what you want to do is to be in a
specific directory. So if you don't know
how to navigate there, all you need to do is open a
file explorer like Finder, and let's say I'm here inside projects and I
have personal and work. So I could, for
example, go ahead, right click personal
and from services, I can open up a new
terminal windows at a specific folder, or because I'm using
Ium, I can use this. So we're going to
see here that we are now inside
projects personal. I can use here the PWD command just again to check
where we are. So we're users Valentin
project personal. And of course, you
can go ahead and with the upkey go through the previous commands
that we have executed. I can bring this MKDR command
back up, run it once again. Now, if you're taking a
look in the file system, you're going to see
we have personal, we have Test two, we have
a subdeer, subdear two. So these are all available here so we can take a
look at them as they are. So this is exactly
what this command has done and imagine
how many steps you need to take to just create this simple
folder structure here.
4. Navigating through folders: So if you're just getting
started with a terminal, probably using the existing file system to open a terminal in a specific folder is probably the easiest and
the fastest way for you. But just in case
you want to learn something slightly more
advanced, in this tectu, I'm going to show
you how you can list the files and folders in
a specific directory, but also how you can
change the directory. Right now we are inside project
personal and we can use the LS command to list all the folders and files
that are available here. So you're going to see here
there is this folder here, which is called Test two. We can use CD to go
inside Test two. And most of the time, what I do, I don't even type
the entire name. I just type the first part. So example, I'm typing here T E. And then I'm pressing tab, and this will be auto complete. So after that, I'm
going to press Enter, and I'm going to see
here that we are now down one level into
this sub folder, so we can use the LS command
to see what's inside there. It's subdear we can use CD, subdear I'm going to change
the directory once again. We can use PWD. Is like your terminal
is not going to show you this full
path like Min does. So this is why the PWD
command is useful, just understand where you are. Now, let's just assume we want
to go up in the structure. So for example, we want
to go from subder one. We want to go here
inside projects. And there are a couple
of ways to do that. I'm just going to show
you this level by level. So we're going to
write here CD, space, dot, dot, and we're going
to go one level up. Notice on my computer
how this is changing. And then again, CD dot, dot, going to go
again one level up. And then Cd dot, dot. We are now inside projects. So if you use LS,
you're going to see here two folders,
personal and work.
5. Using brace expansion in commands: Next, I wanted to show
you how you can create 100 directories with
just one command. So you now know how to
create one directory, at least three
directories at once. But I want to show you
how you can create pretty much an infinite
number of directories. And if you think I'm
kidding, no, not at all. What I'm going to show you next going to be very, very powerful. And the way we're
going to do this is by using what's called
a brace expansion. So we're going to use braces to expand some
values, pretty much. I'm going to show you first
how this is intended to work. So, for example, we
can use something like the echo command just to print out what this expansion will do. So in this case, we can
have something like this. We can have a list
of different values. So for example, we can have
fo and par a two values. So this is what's
called an expansion. So if we use the echo command, it's going to print
out these two values. But the interesting
part is now if you're trying to create,
for example, a directory. So let's go ahead
inside personal, and we're going to
use here the make directory command to create
two directories at once, so we can use here Fu and bar. And if we're taking
a look here inside, we're going to see
now that these two directories have been created. But this is not even the
most interesting part. The most interesting
part is when we use a sequence.
What is a sequence? Let's take a look at,
for example, echo. We can write here something
like one dot dot, 100. So let's see what this does, and this prints out
the numbers from one up to 100 without us having to manually write each number. So this can be again used with the make directory command, and we can say, Hey, we want to have here different directories. So let's stay here when have
these directories 1-100. There need to be two dots here. Don't put a dash or
anything like that. Don't put any spaces. Is to be exactly as you see it
right now on the screen. And if we use the LS command, we're going to see here now, we have a list of directories all created with just
one simple command.
6. Creating folders and subfolders with one command: Now, just seeing a list
of directories number 1-100 can be useful
in some cases, but it's not exactly what I'm using in day to day situations. So let me show you a
more common scenario. I'm going to go ahead and clear everything that
is on the screen. G to use the CDspace dot
command to go one level down. I'm going to go here
into the directory, which is called W. So
let's say inside work, we want to create here some directories which
have the name Project one, Project two, and so on. And each one should
have different folders like to do bending and done,
just to give an example. So this is when this command can be very useful
because we can use the M directory command to
create an entire structure. So this is why we're
passing this FlagP. Let's say we want to
call our projects like Project and then maybe
add an underscuare, and we can say, Hey,
we have projects 1-20, and then inside each project, we have some folders. For example, we have a folder,
which is called to do. We have a folder, which
is called pending, and we have another folder
which is called done. So with just one command, we're going to
create 20 folders, each of them containing
three subfolders. I'm going to go
ahead and run it. And let's just use Finder to take a look at
what we have created here. So this is my word directory. So these are all the projects
that have been created. And let's just go
into a random one. You're going to see
here each random one, for example, Project four, as done, pending, and to do. So this can simplify quite a lot the creation of a more
complex directory structure. Sometimes you may need
to have, let's say, a series of commands to create the exact directories
that you want to do. But I just wanted to show you
what is the basic concept.
7. Searching and re-using commands: So right now you have this
command on the screen, so you could just press
the upkey to reveal it. But maybe you're coming back to this next week and you
don't know exactly Oh, my God, which command
have I used to do this? So let me show you what I do. First of all, I'm
going to assume that the screen is now clear, so we do not see any commands, and we just have
so many commands, we cannot find that one anymore. So what I'm using here is the key combination
Control plus R, and you're going
to see here it's starting this search here. So it's sometimes called a reverse search or
a backward search. It doesn't really
matter so much, but you're going to see here that's waiting for something. So we can type in
something like KdR and it's going to bring back one or the previous commands
that we have executed. If it's this command that
we seeing right now, it's not exactly the command
that you wanted to see, all you need to do is press
Control plus R once again, and it will bring back one
of the previous commands, and so on and so forth. I just going to iterate through
all the previous commands that contain this
particular string that we are providing here. And if you're happy with
what you want to run, you can still
press, for example, the right error key to
make some changes to it. But otherwise, if you don't
want to make any changes, simply press Enter
on your keyboard and that command that has been
found there will be executed. So I hope that the
tips that I've shown you in this course are useful and that you manage to apply this
to whatever you need. And if you have any
questions, let me know. I'm looking forward
to see what kind of fol structures you're creating by using
these simple commands.