File Permissions
File Permissions
File Permissions
Each file has defined permissions for the file owner, file group and others.
Others are all of the users which do not belong to the file group and are also
not the owner of the file. Each of these has a set of three characters
representing the file permissions.
r represents read permission. If it is set on a file, that means that you can open
and read the contents of that file. On a directory, this means that you can use ls
to list the contents of that file.
w write permissions let's you edit file contents. If it is set on a directory, that
means that you can add, remove and rename files within that directory.
x execute permissions is usually set on executable files, which means that you
have the authorization to execute them. Those are usually binaries, executable
programs and scripts, just like the commands we use from the shell. On a
directory, this permissions let's us enter it with the cd command.
You can change the file permissions with the chmod command. You have two
modes which you can use to change them. Symbolic mode lets you change
permissions by writing letters. First you need to type which set of permissions
you want to modify. u for user (which is the file owner), g for group, o for
others and a for all of them at once.
Than you can define which permissions you want to set. You can do this with
the = sing following the wanted permissions like rwx. You can also just add
some permissions with +, e.g. u+x will add the execute permission to the file
owner. Same goes for removing permissions with -.
After that you need to put the name of the file you want to modify.
There is also a numeric mode. Each permission has an assigned number. x has
1, w has 2 and r has 4. By combining these numbers, you can set the
permissions on a file. In this mode, you are setting all of the permissions at
once, so you don't need to define which set you want to change.
$ chmod 766 filename
This example will change the permissions to 776. This resolves to rwxrwxrw-.
r(4) + w(2) + x(1) gives us rwx(7). This is set for file owner and file group. The
last number is 6 because r(4) + w(2) is rw-(6).