Hello everyone. Now that you have learned how to
assign permissions to file and directories using
letters, but now do you know you could also assign
permissions using numerical values? Yes, so every
time you have a file, you could assign permission
to that file or directory using numerical digits.
And how does it work? So, you know, chmod ugo,
is for user, group, and other, plus r to a FILE
would actually assign a read permission to
everyone. If you want to use in a numerical way,
you could do chmod 444, and the FILE, which
will assign exactly the same permission, as in the
first command. And the end result will be read,
read, and read permission only to everyone for a
file. Now, how does that 444 changes and assign
that permission? Let's look at it by looking at
the structure of a file. So as you all know,
owners assign permissions on every file and
directory, and we have users, and they have three
type of permission read, write, executable. Group has
three type of permissions, and everyone else or
others or all have those three type of permissions
as well, so we all know that. Then let's go more
specifically that the first three bits that we have
already covered are for users, the owner of the
file, the secondary bits are for the group, and
the last three bits are for the others. Now,
moving on, the table below that I'm going to show
you are is actually, assigns numbers or permissions
to the permission types. So let's look at that
table. This is the table is something that you
need to remember. Now, if you have zero assigned,
that means no permission, a one is for executable,
two is for write, three is for execute plus write,
four is to read, five is to read and execute, six
is to read and write, and seven is to read or write
and execute. Now how does these all seven
numbers, all eight numbers work. If I have, if
I do chmod 764 to our file, then it means the
first digit will always be for the user itself. So
seven meanings, if you look at the table, it means
this is going to assign read, write, and executable
permission to the owner of the file. The second
letter, which is in this case is six, it means
that a read and write only and that will be
assigned to the group. And the last one is for
that is for others, and the four means only read,
so only read will be assigned to the file. So
again, first digit is for users, second digit is
for group and third digit is for others. So let's
try in our Linux machine, in our lab machine, and
see how it works. So I'm going to create a file,
let's say, sam, and we're going to touch and
create a file sam. I will do ls -ltr.
and the file is there. By the way, I am logged
in as myself, and I am in my home directory. So
let's clear the screen by typing clear, and do ls
-ltr again, and you will see the sam file is
all the way at the bottom. Now by
default, I have given the permission as read, write,
read, write, and just read. If you want to change
this permission to 764, meaning me as myself would
have read, write, and executable. And group will have
only read, write. And everyone else will just have
read, then all I have to do is chmod 764 sam.
Now when you do ls -ltr, you
will see right at the bottom, I have now read, write,
executable, read, write for the group, and just read
for everyone else. Now if I wanted to remove those
permissions, let's clear the screen and just do ls
-ltr only on sam file so just only that
file shows up on the list. If I wanted to remove
every permission of everyone else,
I will do chmod 000 sam, do ls -ltr by
hitting up arrow key, which will bring the last
ran command, and you hit enter. You will see all
the permissions are gone. Now, if I wanted to,
let's say if I want to assign, read and write
permission only to myself, then how are you going
to do it. Then all you have to do is chmod,
myself would be the first letter, remember, the
first, sorry, the first digit. So I just want read
and write only, so that would go for number six.
Because if you look at the table, number six only
gives read and write. Then the rest, I don't want
to assign anything else. So you cannot leave
anything empty like that, so you have to leave 00.
So no permission at all, type it, sam. Now if you
do ls -ltr on sam, you'll see I only have
read and write. So let's try one more time. What
if I want to keep the permission read and write
and I wanted to assign read permission to the existing
permission for others? Meaning, right here, the
last three bits I want r here. So for that, I
would do first of all chmod, and of course, I
want to keep the permission and that permission is
six. For group, I don't want to assign anything.
And for others, I want only read. And if you look
at the table, the read, number associated with read
is four. So if I do hit four, and type sam, and
now if I do ls -ltr on sam, and you will see
read and write, and read is only given to others in
this case. Let's look at one more, and last one
example, what if I want to assign executable
permission to everyone in the system. So
you do chmod, now what's the executable? The
executable permission, if you look at it, it's
number one from the table. So that means 111.
Because I want to assign executable to myself, to
groups, and to others, so 111 and sam file, done,
let's do ls -ltr, and you will see it's
only given xxx, so now you can only get executable. If
you want it to have executable and read, then you
would have given number five, and 111, which will give you
[No audio]
yourself executable and read, and the rest
only executable. Anyway, that's how you use this
table. Or that's how you use the numerical letters
or sorry in numerical digits to assign permissions.
Also, if you do not remember this, this chart, or
if it's not handy with you, you can also go online
there are many calculators online that you could
use you. All you have to do is type online
chmod calculator and it will come up. A lot
of websites have those free calculators for you,
all you have to do is click on the ownership or
group or public meaning others whatever that you
want to do, check those marks and at the bottom,
you will see Linux permission, it will give you
the exact number that you need to type it in for
chmod, it's very easy. Anyway you could do,
either way you could do using the
letters or you could do using the digits. I just
want to cover both methods so you understand how
the permission works using both methods.
[No audio]