Now why don't we understand a little bit more about those
nine bits that are dedicated to our glorious file
permissions? So we have the read permission.
Now the read permission, obviously, is going to be r in the symbolic format.
But if we're looking at in the numeric or octal format,
it would be 4 represented by 100 in binary.
Being able to read a file,
of course, means we can read the file content. From a directory point of
view, we're able to list what a directory contains.
When we look at the write permission, again,
that's going to be indicated by a w when we look in
the symbols. In the octal format, it would be a 2 represented as 010 in binary.
Being able to write to a file means that we can add content to a file.
Being able to write to a directory means then that
we can write to the directory.
Writing to a directory means adding and deleting
files through to that directory.
The execute permission is then shown as the x when we go through
and take a look at it in the symbol permissions. It would be a 1 in
octal. So that gives me 4, 2, and 1.
If we add all of those together,
we get a 7, 7 is our maximum value that we can have in
an octal notation, 0 through to 7.
The execute permission, of course, is going to be
represented by 001 in a binary.
Execute on a directory means that we can enter a directory.
That's really important.
And, of course, to a program or a script,
it means that we can execute that program or script.
The default permissions are 666 for a regular file,
so that's going to be read/write, read/write, and read/write.
The permissions are going to be granted through to the user group and others.
The default permissions for directories are 777.
Read, write, and execute all the way through for user group and others.
But that's often not the permissions we see when we
create a file or a directory.
So what's going on here?
It's the umask value.
The user mask can be changed by the user themselves, and this
then will affect the default permissions.
So our effective default permissions are controlled by the umask value.
The default umask value very often is 002, removing
the write permissions from others.
Do you want to see this?
Do you want to learn a little bit more?
I think you do. Come on,
let's go through and just take a look at what we mean by our
umask value and what we mean by default permissions. Now
this really isn't too difficult,
is it? Default permissions are just going to be the default permissions.
And what did we say for a regular file?
It's going to be 666.
So if I go through then and touch file1 and then go through and do an ls ‑l
on file1, we can see then that we don't get 666, do we?
We get read/write, read/write, and read. We've lost
the write permission for others.
If I look at my umask, my umask, don't worry about the leading
0 at the moment, but we can see it's 002.
So we're not removing any permissions for the user, no permissions being
removed for the group, but we're removing the permission 2. The
permission 2 is our write permission from others.
If I set my umask to be 0, I can type umask again, so you see
there's nothing weird in just setting it to 0.
But now when I go through, I will touch file2, and
then we'll run an ls ‑l on our files.
So if I do file and an asterisk, we can see there the
difference between file1 and file2. File2 then has got 666,
the sign of the devil, read/write, read/write,
read/write the default permissions.
If I go through and create with mkdir and then dir1, and then do an ls ‑ld,
don't forget to use the ‑ld when we're looking at a directory.
Otherwise, we look inside of that directory, and we can then go through
and see that we've got 777 all of the way through.
Being able to set your umask gives you the control so that you can then go
through and specify the umask that you need for a particular session to be
able to minimize the amount of changing permissions that you need to do.
It's a little bit like the cd command.
We use the cd command because we're going to be
working with a whole load of files.
We use the umask command so we can minimize the amount of changing
of permissions that we need to set. If I need to make a file maybe
private so it's only accessible to me, if I go through and set the
umask to be 77, again, let's review that with the umask command, so 0077.
If I now go through and touch file3, ls ‑l on our file3, we'll do
the file* so we can compare all. And we can then go through and
see, now when we look at file3, it's accessible to the user, but
not to the group or others.
So whilst my umask is currently set to 77,
I know then that files are kept private just to myself,
the user owner, and neither the group nor others are going to gain access to it.
It's really, really useful and obviously something that we could consider setting in our login script.