Understanding Permissions on a Linux System

ls -l
Outputs something similar like this
drwxrwxr-x 10 rocktim rocktim 4.0K 2022-03-11 22:00 work/
The permission string(drwxrwxr-x
) can broken down into four different pieces.
-
The first section denotes to the type of the target whether it is a file or directory. If the the first section is
d
that means it's a directory. If it's a-
that means it's a file. -
The second section refers to the the
user
's permissions ie.rwx
. Meaning the user hasread
,write
andexecute
permissions over that specific file/dir. -
The third section refers to
group
's permissions. In the above example the grouprocktim
has permission toread
,write
andexecute
on that specfic dir. -
The last section denotes to permission of others ie not any valid user or any group. In the above example other have permissions to
read
andexecute
only but does not havewrite
perimission that's why we see a hyphen(-
) there.
How to change permissions of any of dir of file
To change the permission of a specific file/directory we run the following command against the targated file
chmod +x testDir
Here we are grating permission of execute
to everyone. If we want to be more specific of our permission. Say we only want to add permission for user not anyone else.
The we can do that with the u
option before the +x
chmod u+x testDir
The same way if we want to add permissions for groups we will replace u
with g
and for others we will use o
.
Also if we want to remove permissions we can simply use -
instead of +
when running chmod
and everything else works the same way.