University of 
Pennsylvania
School of Arts & Sciences
SAS Computing servicesstaffsearchFAQ
   


How do I change permissions on a file?

This page will cover the following:


[top]

Introduction to permissions

There are three basic modes to files and directories:
  • (r)eadable - Value: 4
  • (w)ritable - Value: 2
  • e(x)ecutable - Value: 1
Additionally, each of these modes can be applied to the
  • (u)ser
  • (g)roup
  • (o)thers

The user means you, the person who owns the file.

The group refers to a determined group to which you belong. Most students will belong to a group called "sasugrad". To find out what groups you belong to type groups at the unix prompt. If you want to create your own special group of users, consult the man page for chgrp

The other means everyone else or world.


[top]

How to determine current file permissions

You can determine the permissions on files by executing the ls -l command. The leftmost field for each file will contain the permissions of the files.

The first space is reserved to show whether or not it is a file or a directory. The next three spaces are the permissions for the user. The next three are for the group and the last three is for other.

As an example:

help@sas(/gla/help)% ls -l

-rw-r--r--

1 user

group

273

Mar 24

11:28

file1

-rwxrwxrwx

1 user

group

1449

Jan 29

14:01

file2

-rwx------

1 user

group

4119

Jan 26

13:22

file3

File 1 is readable and writable to the user, and readable to everyone.
File 2 is readable, writable, and executable by everyone.
File 3 is readable, writable, and executable only to the user.


[top]

Changing permissions of everything in your html directory

To change the permissions of every file and directory in your html directory so that they are readable to all:

  1. At the MAIN MENU prompt, type:
    unix and press the enter/return key.
  2. At the unix prompt, type:
    permissions and press the enter/return key.
[top]

Changing permissions using letters

In unix, to change the permissions of a file, use chmod, with the following syntax:
% chmod [who][op][permissions] filename
[who] refers to the users that have a particular permission: the user ("u"), the group ("g"), or other users ("o", also known as "world").

[op] determines whether to add ("+"), remove ("-") or explicitly set ("=") the particular permissions.

[permissions] are whether the file should be readable ("r"), writable ("w"), or executable ("x").

As an example:

% chmod u+x file1
will add executable permission for the user to file1.
% chmod o-w file2
will remove write permission for others for file2.
% chmod ugo=rx file3
will explicitly make file3 readable and executable to everyone. Note that you can combine the [who] and [permissions] fields to allow multiple values.


[top]

Changing permissions using numbers

As mentioned in the Introduction, the modes readable, writable, and executable have numerical values. These values can be used to change permissions easily by adding these numbers.

The modes follow a hierarchy of user, group, and then others. Using this we can assign three numerical values.

For example: to make a file readable to all, executable to the group and writable to the user, just add the permission values.

user = readable + writable = 4 + 2 = 6
group = readable + executable = 4 + 1 = 5
other = readable = 4

So to change the permission, type:

% chmod 654 filename
For more information on changing permissions, type man chmod at the unix prompt.


Make a New Search

Enter your query below to begin.



Last modified: Tuesday, 28-May-2002 10:03:37 EDT