File Permissions: a Tutorial

  • see Commands, Processes, and Files
    this is a thorough description of unix files

    File Permissions: "How & When to Use the chmod Command"

    (adapted from "UNIX Unbound," by Harley Hahn)

    Understanding File Permissions

    There are three types of permissions:
    1. Read Permission (r)
    2. Write Permission (w)
    3. Execute Permisson (x)

    File Permission vs. Directory Permission

    Read, write, and execute mean slightly different things in relation to files and directories.

    File Permission

  • Read: you can read from the file
  • Write: you can write to the file
  • Execute: you can execute the file

    Directory Permission

  • Read: you can read the directory
  • Write: you can create, move, copy or remove entries
  • Execute: you can search the directory

    The Three Sets of Permissions

    Permissions are specified for:
  • you, the user (or userid)
  • your group (or groupid)
  • everybody

    Displaying the File Permissions

    You can display the files or (sub)directories within your working directory and view the permissions by using the following command (at the ecom prompt):

    ls -1

    Along the left side of your screen, you'll see the file permissions indicated by something like this:

    -rwxrwxrwx

    or

    -rwxrwx---

    or

    -rw-------

    The letters "r", "w", and "x" indicate where read, write and execute permissions are granted, while the "-" symbol indicates where permission is not granted.

    Analyzing the Permissions

    To analyze the permissions, divide the 9 characters into three sets of 3: one set of 3 for the owner, one set of 3 for the group, and one set of 3 for everybody.

    File Permissions
    owner groupeverybody
    rwxrwxrwx

    File Modes

    Unix uses a three-number code to represent file permissions. This code is called a FILE MODE, or MODE. For example, the mode of a file with this type:

    -rw-------

    has the following mode:

    File Mode: Permissions for
    owner groupeverybody
    600


    Here's how the code works:
  • read permission = 4
  • write permission = 2
  • execute permission = 1
  • no permission = 0

    Numeric Values for File Permissions
    read writeexecuteVALUE (TOTAL)read writeexecute
    ---0000
    --yes1001
    -yes-2020
    -yesyes3020
    yes--4400
    yes-yes5401
    yesyes-6420
    yesyesyes7421

    Add the Numbers to Come up with the Permission

    For each set of permissions, the appropriate numbers must be added together. So, to indicate read and write permission, we add 4 and 2, coming up with 6.

    An Example of a File Permission Combination

    The File
    So, what is the mode for a -rwxrw-r--file in which:
  • the owner has read, write and execute permissions? (r,w,x)
  • the group has read and write permissions? (r,w,-)
  • everyone else has read permission only? (r,-,-)
    For this example, the "equation" would be:
  • Owner: read + write + execute = 4+2+1=7
  • Group: read + write = 4+2+0=6
  • Veryone: read = 4+0+0=4
    The mode
    The mode for this file is 764.

    Changing File Permissions

    The command to change the permissions is chmod. This stands for "change mode." You can use this command with numbers or letters.

    Changing the Mode Using Numbers:

    Syntax
  • chmod 755 survey.html
    this indicates a change of mode to mode 755 for the file named "survey.html".

    Changing the Mode Using Letters:

    It is possible to use another system to change mode, using letters instead of numbers to indicate the changes. The command
  • chmod o+r survey.html
    for example, indicates that you wish to add read permissions (+r) for others (o). Using this system, the following letters refer to:
  • u represents "user"
  • g represents "group"
  • o represents "others"
  • a represents "all"
    Back to NEIU CGI Workshop Main Page