• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL

Chapter 20. Using Basic Unix Commands > Changing Permissions for a File or Dire...

Changing Permissions for a File or Directory

A file's permissions are what allow it to open when you double-click applications to use and folders to open. They're the little security guards that instruct the file what it can and can't do. In general, the files that you create aren't accessible to other users. However, UNIX allows you to explicitly make your files available to others. Each file in UNIX has an owner—normally the user who creates the file. The file also belongs to a particular group. A group in UNIX is a set of users. Type the command groups to see what groups you are a member of. Each user can have read, write, or execute permissions to the file (r, w, or x). These permissions are set and modified by the owner of the file. Read permission allows users to view the contents of a file and to copy it. Write permission allows users to modify the file. Execute permission allows users to run the file if it is executable. The current permissions for a file can be listed using the ls -l (lower case L) command. To modify the permissions of a file or directory, use the cmod command. Commands are connected with a plus sign (+) to add permission, or the minus sign (-) to remove permission.

Change Permissions for a File or Directory

Open the Applications folder, double-click the Utilities folder, and then double-click the Terminal icon.

Type one of the following codes on the command line, and then press Return.

  • File chmod ug+r filename.doc

    The owner (u) and group (g) have permission to read the filename.doc file, located in the active user's directory.

  • Directory

    cd /Users/username

    chmod a+rx *

    The cd command moves the user to the username directory, and the chmod command allows all users (the letter a can be used to replace the u, g, and o attributes), the ability to read and execute all files (* equals all) in the active directory.



Not a subscriber?

Start A Free Trial

  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint