NACSE - Northwest Alliance for Computational Science and Engineering
Next 5.M: Review Quiz  Up 5: Managing Files and Directories  Prev 5.L.1: Looking at File Permissions  Contents

Basic

§ 5.L.2: Changing File Permissions


Now that you know what your file permissions are, it's time to modify them. The "change mode" command chmod changes the permissions of files as dictated by the command arguments. There are a number of ways to state the arguments for the "change mode" command.

One way is to give the command followed by the permission access you would like to change and the name of the file to be affected:

For example, let's say we want to change permission for the file area.f in directory development/prog. First we get to it and check what's there:

> cd ~/development/prog
> ls -l

-rw-r--r--   1 melanie users         68 Mar  3 13:18 area.f

We see from listing that melanie has read and write permissions, while the group and outside world have only read access. To change a file's permission access, you enter the chmod command with arguments giving the party affected, whether you want to add ore remove permission, and finally the set of users affected. For example, change the file permission of area.f to allow everybody to execute it, and for the group to write to it, and check the result:

> chmod a+x,g+w area.f
> ls -l

-rwxrwxr-x   1 melanie users         68 Mar  3 13:18 area.f

Here the a+x argument added execute ("x") permission to all ("a"), and g+w argument added write ("w") permission to the group ("g").

Let's imagine now that you got tired of political correctness and no longer wanted to be a group player. You want to remove the write and execute permission given to the group and the world, but still maintain your own full access:

> chmod g-w,go-x area.f
> ls -l

-rwxr--r--   1 melanie users         68 Mar  3 13:18 area.f

Now the "-" is used to remove permissions from the indicated parties. The listing shows "-"'s for your group and others, and this means permission is no longer available.

Now that you have mastered one method, we'll show you another one which changes all permissions with one simple argument to chmod. This method is faster, but requires a little calculation.

The graph at the right shows a way of representing file permissions for each of the groups. The scheme is easy to remember, if you remember that it is based on the first three powers of two: 1, 2, and 4.

Although it may seem hard to believe, the full set of permissions for any one file is obtained by adding these numbers together! Because there is only one way to get to each permissible number, its meaning is unique.

For example, a permission of 421 = 400 (read permission for the user) + 20 (write permission for group) + 1 (execute permission for others). Likewise, 455 = 400 (read permission for the user) + 40 (read permission for group)+ 10 (execute permission for group) + 4 (read permission for others) + 1 (execute permission for others).

In order to change file permission, you enter this numerical code as the argument to the chmod command>. For example, with the code above:

> chmod 455 area.f
> ls -l
-r--r-xr-x 1 melanie users 68 Mar 3 13:18 area.f

Notice how all of the file permissions have changed at once, unlike the previous method in which you change one at a time. This is really clever!


Next 5.M: Review Quiz  Up 5: Managing Files and Directories  Prev 5.L.1: Looking at File Permissions  Contents

Comments and questions to Dr Elias N. Houstis enh@cs.purdue.edu.