[No audio]
Creating files and directories. In this lesson we
will cover how we can create files and
directories, different ways to create files. The
first one is the touch. The touch command creates
a file that is, of course an empty file. The
second way to create a file is if you are copying
an existing file and creating a new file at the
destination location. And the third way to create
a file is through vi command. vi is our editor,
which we will cover in detail later in the
lessons, but I will cover quickly how we could
create a file using vi. Creating directories, the
easiest way to create directory in the command is
mkdir which is make directory. So now let's get
into our Linux machine, and we will use every
command listed here as a practice to create
files. Okay the first thing we have to do is to
find out what user id we are logged in as. So you
do whoami, and it will tell you you are logged in as
yourself. And then the second thing you have to
know which directory you are in and I am in my
home directory. Now I have, I will be creating a few
files and as your homework I want you to create
those files and directories as well. The first way
to create a file, here I have a list of
files that I will be creating.
[No audio]
We will use the first command to create a file
will be touch, okay. touch space, I have here jerry,
hit enter. When you hit enter and you get the prompt
back that means your command worked. Now how do we
know where is that file? You do ls -l, and you
will see here the directory you have is right here,
jerry. Sorry not directory, the file. Now I want
you to create another file, touch kramer. Again
check if it's created. Yes it is created, jerry and
kramer. Now I use the option ls -l which will
list all the files and directories in alphabetical
order. If you want to list all the files or
directories that are created, and when it was last
modified, you will use ls -ltr which means
give you everything by the timely order, and in
reverse meaning the oldest one at the top and the
newest one at the bottom. Then you hit enter, you
will see jerry was the first one that was created,
followed by the kramer.
[No audio]
Next one we are creating is george.
[No audio]
How do you verify the file was created? You
do ls -l.
Now these files can be changed or renamed or
moved. But we'll go to the next set of files to
create I want you to use this time to copy command.
So I want you to use cp jerry, and then the
destination file I want you to be lex. Do ls minus
ltr. So what exactly did it copy? This jerry file and
named it lex. I want you to do the same thing for
clark. So cp jerry or kramer or whichever file
and do clark.
Same thing cp jerry and lois.
Now let's verify we have all those files. There you go.
We got all six files. So now three files we
created with touch command, three files we created
with the copy command, and the rest of the files
we'll create using vi. Now remember, vi is a very
tricky, so I will only create one file and we will
cover the vi later. So vi space homer. So hit
enter. Once you hit enter, it will bring you to
file editor. Now be very careful what you type in
here, because you will not be able to get out if
you really don't know what you are doing. So at
this point, I just want you to do Shift colon, w
as in write, q as in quit, and exclamation point,
which is also referred as bang, hit Enter. The
file homer is created. How do we verify it?
Let's do ls -ltr, and there you go, the
homer file is created. Now the other three
files, I will create by the touch command. Now you
will notice, you don't have to run touch command
over and over again, you could run the touch
command just once and do bart space lisa space
marge, marge. So now with this just one command,
it will create three files. So hit enter. Verify
all three files bart, marge, lisa, all of them are
in this directory. Now, the next step I want you
to do is create directories within your home
directory. So just do pwd just to make sure you
are in home directory. Then from here, you do mkdir
space seinfeld.
[No audio]
Now the directory is created
because you got, you got your prompt back, how do
you verify it, ls -ltr. And you'll see at
the bottom,
that's where the directory is created. And if you
notice, some of the Linux distributions also
change the color for you. So this way, it will be
easier for you to identify which one is the file
or which one is a directory. Same way I wants you to
create another directory mkdir superman, and
again, you could also do the same way. Instead of
running command one command after the other, you
could just run one command and followed by two
different directories. So the second directory we
have is simpsons, simpsons.
[No audio]
And hit enter. Once you
hit enter, so ls -ltr, see all three
directories at the bottom. And you have all your
files right here, listed here. So this is the way
you create files and directories in your home
directory. If you try to create a directory in
let's say, slash or somewhere else where you do
not have permission, it will tell you that this
directory, you don't have sufficient rights to
create that directory. So let's take the example
if you go to cd slash etc, and I want to create
a file here, let's call it test123 and hit enter.
It's going to tell you, you do not have permission
to create that file in there because we don't own
slash. Who owns the slash? root owns it, and you are
not root. Who are you? You are yourself in this case
iafzal. Again, we learned three, four commands
touch, cp, vi to create files, and the last
command we learned to create directories is mkdir.
[No audio]