Instructor: 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, change mod ugo is for user group
and other plus r to a file
will actually assign a read permission to everyone.
If you want to use in a numerical way,
you could do change mod 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 the 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 permission
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 permission 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 second three bits are for the group,
and the last three bits are for the others.
Now, moving on, the table below that I'm gonna show you
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.
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 four seven numbers,
all eight numbers work?
If I do change mod 764 to a 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 read and write only and that will be assigned
to the group and the last one is four.
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 user,
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, I'm 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 wanted to change this permission
to 764, meaning me as myself will 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 change mod 764 sam.
Now, when you do ls -ltr, you'll 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 permission,
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 change mod 000 sam.
Do ls -ltr by hitting Up arrow key
which will bring the last ran command.
And you hit Enter, you'll see all the permissions are gone.
Now, if I wanted to, let's say if I wanted to assign read
and write permission only to myself,
then how are you going to do it?
Then all you have to do is change mod 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 zero, zero.
So no permission at all, type 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 are here.
So for that, I would do first of all, change mod
and of course I wanted 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,
you'll 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 wanted to assign executable permission to everyone
in the system?
So you the change mod.
Now, what's executable, the executable permission,
if you look at it, it's number one from the table.
So that means 111 because I wanted to assign executable
to myself to groups and to others.
So 111 and samp and let's do ls -ltr,
and you'll see it's only giving xxx.
So now you got only executable.
If you wanted to have executable and read,
then you would have
given number five and 111,
which will give you,
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,
numerical digits to assign permissions.
Also, if you do not remember this, this chart,
or if it's not handy with you, you could also go online.
There are many calculators online that you could use.
All you have to do is type online
change mod calculator and it will come up.
A lot of websites have those free calculators for you.
All you have to do is pick,
click on the ownership or group or public, meaning others,
whatever that you want to do, check those marks
and at the bottom, you'll see Linux permission,
it will give you the exact number
that you need to type it in for change mod.
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 wanted to cover both methods,
so you understand how the permission works
using both methods.