In this video, you'll learn how to create files and directories inside
Linux.
Our plan is to explore how Lennox handles files and
directories.
We will discuss our files and directories have ownership and permissions that
could be used to gate access.
Finally, you will use a couple of commands to create your own
file and directory. Let's get started. Okay. So
here we are back in the terminal and as you recall from the
last video files and directories make up the
Linux file system creating files and directors are
actually pretty easy in Linux.
Each file and directory is associated with an owner
a group and has permission access rights for
three different types of classifications and those classifications
are user group and other this
will make a little bit more sense as we go ahead and
look at some. So let's go ahead and look at a file for permissions. I'm going
to start right here in our home directory since that's
gonna be easiest and if remember if you remember we use the ls
command to list the contents of a directory.
Right now it doesn't look like there's anything.
But if we use the dash a command that'll list
all files and directories that includes anything hidden and
so we'll go add the L for the long listing.
So it's easy to read on the output.
And as you can see here, there are there's seven
items here and six of those are files and
one is a directory.
And so we'll focus on the file right
now called bash RC. If you aren't familiar
with the dot bash RC file, it is basically a the configuration
file for your bash. Shell. We
will get into bash and The Bash and
Bash scripting in the next section.
So think about this right now all these
are there's a lot of information here, but this is kind of broken up into
columns. And so you have column one.
You can forget about column two for right now column three
and column 4 and then you have the rest of these columns
and then obviously the last column which is the file name. We're gonna
focus on column one column three and column 4.
for this video
So the I'm actually gonna work a little bit backwards here
so column four, which is highlighted right now. This
column is the group. So this
is the group.
Of this file. So this file belongs to
this group column three over here is the user. And
so that means that ec2 user
which if you recall is the default user created
by Amazon Linux
And it's not by an accident that the group is also
named bc2 users. So when you create a user by
default, you will get a group name the same as the username and we
will explore those later in another section when we cover
users in groups.
So here the ec2 user is the
owner of this bash RC file, which makes sense,
right? Because it's in the ec2 user directory. You
would expect it to be owned by that user.
So let's go look over here in column one. So
column one is a set
of permission and these permissions are broken into
three different classifications. Like I said earlier user
group and other
the first Dash right out here is
what it is called file type and it basically
tells us what type of file it is. And if you look down here
on the data SSH, it has a d which denotes
directory but we'll get to that in a second. You can
see here the dash meaning that it's just a standard file.
It's not set the next three characters here.
Are their permissions for the user classification?
and what the
Options you have here for your permissions and
I'll write this out right now is read right and
execute denoted by the rwx. And
so they do exactly what they say.
You can read permission you have a right permission.
You have an execute permission. So if we look at our back at our Bashar C
example here, you can see that the first
three characters we have read and write
or set but the X the execute bit is
not set that's denoted by the by the just the
the dash there.
The next classification which is the group classification,
you can see that we have the r bit
the read bit set, but no right or execute
it and the last classification which
is other which kind of means any anybody else.
You can see that the read bit is set but they're
right in execute better not set very similar to group.
Okay, so let's talk about the files put this all together just for the
file.
We could see here that the ec2 user
who is the user of this file the owner
you could say.
That person can read and write to this
file which makes sense because it's their file.
If you are a user inside the ec2 user
group.
You have the read permission of this file meaning you can read any
of the contents of that file.
And if your other anybody else that not of
those two classifications you can read this file as well. So
that is the basic overview of file permission.
So let's take what we just learned about there about ownership
and permissions. And now let's talk about that in
the context of a directory.
So like I said before the D out here, lets us know the
file type which is a directory and this dot SSH
directory. Just if you're not familiar with it, this contains all of
your information either a local SSH config and your
SSH key. So this is sensitive information that you
would want protected. You wouldn't want anybody to be able to just
read this right only the owner of these files
inside this directory.
And the director itself, of course, so you
can see here in our first classification which is the user we have
rwx which is read right execute. And
then if you look at the other two classifications the
group
and the other
none of them are set by the dashes. So only so
the way that this reads is only the
ec2 user who the owner of this
directory can actually read write and execute anything
and anything to do with this directory.
So that is the basic file
permissions and file and
directory ownership on a Linux file system.
Obviously, there's a lot more you can cover here, but I wanted to
keep it high level for brevity.
We'll explore ownership and permissions.
When we get into users and groups.
We're going to use a few commands called touch make their
MV RM and CP
to manage files and directories as we
go through this lesson.
Don't worry about if you're not familiar with a lot of these commands. I'll we'll
use all of them. I'll tell you what they
are. So you get a little familiarity with them. So let's start off
with the touch command the touch command creates an empty file if
it doesn't already exist.
The make dir command or
mkdir command stands for make directory
creates a new directory.
The MV command moves and renames
files and directories. It's kind of does both the
RM command removes files
and directories and the CP command copies files
in direct. So let's put all these commands to
use. So we're gonna create a directory right here in
our home directory called engineering if by any
chance, you're still not in the home directory.
There's a little shortcut you can do and if you remember the the command we
used earlier which was CD which for change directory if you
just type CD and do not give it any arguments and
hit return. It'll return you to your
home directory every time. Okay, so let me clear the screen.
And we're gonna create our directory and we're gonna use the mkdir
command and we're gonna pass it the name
of the director, which is engineering.
So type that in your terminal and then when
you hit return
we should have a directory created. So let's verify that so
we're going to use the ls command again.
And as you can see here, we have the engineering directory
created and we can knowing what we just learned.
We could go ahead and validate that as well and we're going
to use the dash L here for the long format so you can see the permissions and
ownership.
And as we can see here, the engineering directory was
created its own by the ec2 user and
the ec2 user group which makes sense. That's the
default on that logged in is that user? So when I create it it
uses that
But here's something interesting. So if you look at
Column one here. You can see in this
classifications. The user has read
right and execute. The group has read right and
execute on this on this directory which makes sense. So any myself or
anybody in the ec2 user group can do
all those things can read right and execute stuff in
this directory and then if you look at
The other it's read and execute meaning
they can't write to any of the files in inside this
directory are or right to this directory,
but they can read and execute.
So, okay, so we validated that so what we're
going to do next is we want to create a file inside this
directory. So I'll clear
the screen one more time.
So let's change directory into engineering.
And then we are going to create a file and let's just call it
test.
And we're going to use the touch command for this and like I said touch will
create an empty file if it does not exist.
So you'll type in touch and the file we want to create hit
enter.
And if we just do a quick LS you can
see it's there. If I add the Long View so we can see the
permissions you can see that we created a user just like
the directory it is.
It is by the ec2 user and it is in the
ec2 user group.
And we can see that the user and group can both
read and write to this file, but anybody else can
only read it?
Okay, so at this point we've created a
directory and we have a file inside this directory.
Let's pretend that we made a mistake on the
name of this file and we were meant to name. It contributors instead.
We can use the MV command here to
go ahead and rename this file. So MV
will take the name of the file or the source
and then the the name you want
to rename it as so we'll type MV.
test and then contributors
I can spell it and
we'll hit return. So now if we do
an LS with the long format.
We could see that we have a file called contributors now
and test is no longer there. We've just renamed
it. It has the same permissions the same user and group.
Okay, so from here, let's jump back into our home directory
and we're going to use this the CD shortcut and
I'll clear the screen.
Okay, so let's create another file and this file we're
gonna call config.y ML and this is
basically a like configuration yaml file
if you're not familiar with the ammo don't it's not that big of a deal right now, but
what we're gonna do is we're gonna create that in our
home directory not in the engineering directory.
And we'll touch config.yamo.
And if we do a quick LS we could see that config.yamo and
the engineering directory now in our home directory.
So what we're going to do now is we've realized
that hey we've should actually made
this in the engineering directory. I know these are all
very contrived, but I wanted to make sure that you got exposed
to all the commands and some reasonable light explanations.
We want to make a copy of the config yaml file
and it should be in the engineering directory as well.
So we're going to use the CP command.
And like I said before cop is the CP command
copies of file or directory from a source to a
destination. So we are gonna
we are gonna say the config.yaml file.
We want to copy it into the engineering directory.
So we'll hit enter right there after you
type that in terminal and if we look we still have a version
of the config diama file
in our home directory, but also if I
look in the engineering directory with the long format
of LS
You can see that now we have the contributors file and
we have the config.ieml file and they
have the same permissions same users and groups.
Let's decide that, you know.
We don't really need this in our home directory anymore. It's fine just
to have one copy of it in the engineering directory. So
we're going to use the RM command at this point and this
is the remove command. So removal remove a file or directory.
And so we use RM.
And then we'll use the config and you notice out. We're
still in our home directory not in the engineering directory and
you go ahead and remove config.aml.
And if we do a quick LS we can see that it is now gone.
Okay. So this was the
quick overview of files and directories and
the commands you would use to manipulate them.
You also introduced to ownership and permissions.
So let's jump back over and let's recap
of what we did in this video.
Okay, so let's talk about what we did in this
video.
You first learned about Linux files and directories and how to
manage them. You introduced to ownership categories user
group and other
we also talked about permissions like read right and
execute. These will make more sense later on when we apply
them in another video you use common commands like
touch and make dirt to create a
file inside the engineering directory.
In the next video you will get a crash course
in user management. See you soon.