Changing file or directory permissions

Use the chmod command to change the permissions of your files.

  1. To add a type of permission to the chap1 and chap2 files, type the following:
    chmod g+w chap1 chap2
    This adds write permission for group members to the files chap1 and chap2.
  2. To make several permission changes at once to the mydir directory, type the following:
    chmod go-w+x mydir
    This denies (-) group members (g) and others (o) the permission to create or delete files (w) in the mydir directory and allows (+) group members and others to search the mydir directory or use (x) it in a path name. This is equivalent to the following command sequence:
    chmod g-w mydir
    chmod o-w mydir
    chmod g+x mydir
    chmod o+x mydir
  3. To permit only the owner to use a shell procedure named cmd as a command, type the following:
    chmod u=rwx,go= cmd
    This gives read, write, and execute permission to the user who owns the file (u=rwx). It also denies the group and others the permission to access cmd in any way (go=).
  4. To use the numeric mode form of the chmod command to change the permissions of the text, file type the following:
    chmod 644 text
    This sets read and write permission for the owner, and it sets read-only mode for the group and others.

See the chmod command for the complete syntax.