Setting your file access permissions


This web page describes how to do the following things:

  1. Determining the access permissions for a file
  2. Changing the access permissions for a file
  3. Changing your default file access permissions

1. Determining the access permissions for a file

To see the access permissions on any of your files or directories use the command ls -al filename. You will see something like the following:

-rwxrw-r--   1 tester   staff        3798 Mar 19  1998 file.dat

The first position (here a "-") indicates the file type, the possible file types are:

- regular file
d directory
l link

The following 9 bits specify the permission mode for the file and they are:

For regular files:

r the file can be opened and read
w the file can be modified or truncated (rename and delete access is determined by permissions on the parent directory)
x the file can be executed

For directories:

x the directory can be entered but no files can be listed
r and x the contents of the directory can be listed
r, x and w files can be created, deleted and renamed within the directory

So back to our example,

-rwxrw-r--   1 tester   staff        3798 Mar 19  1998 file.dat

Of the 9 permission bits, the first three permission bits (here "rwx") indicate access for the owner (here "tester"). The second three permission bits (here "rw-") indicate access for the group (here "staff"), i.e., anyone in the same group. The final three permission bits (here "--x") indicate access for "world", i.e., anyone with an account on the system.

To determine the permissions on your home directory type:

ls -ld ~

2. Changing the access permissions for a file

The command used to change the permissions on a file is chmod. It's syntax is: chmod mode filename.

The octal coding for the permission bits (or mode) is:

PermsOctalPermsOctal
---0r--4
--x1r-x5
-w-2rw-6
-wx3rwx7

Again the first mode is for owner, the second for group, and the third for world. So if we wanted to change file.dat to be accessible only by the owner we would use the command:

chmod 700 file.dat This would result in
-rwx------   1 tester   staff        3798 Mar 19  1998 file.dat

If you wanted the file to be readable by anyone in your group or anyone on the system. Or if this is a web document. You would use the command:

chmod 644 file.dat This would result in
-rw-r--r--   1 tester   staff        3798 Mar 19  1998 file.dat

If you want to change the permission of files in a directory tree you can do this recursively via the following command: chmod -R mode directory-name

3. Changing your default file access permissions

To change your default file access permissions (i.e., the permission on files that you create), you need to set your file creation mask appropriately. This is accomplished by adding the umask command to your ~/.cshrc file. The syntax is: umask mask

Where the octal coding used by the umask command:

PermsOctalPermsOctal
rwx0-wx4
rw-1-w-5
r-x2--x6
r--3---7

Again the first mask is for owner, the second for group, and the third for world.

So if you want your default file access permission to be that only the file owner (you) can read or write the file, you would should put the following command:

umask 077

in your ~/.cshrc file. Note, this will only affect the permission of new files that you create, it won't change the permissions on existing files. Use the chmod command described above to change existing files.


Physics Computer Services, pcs@physics.ucsb.edu
Last Modified: September 23, 1998