Changing Permissions for a File or Directory


Unix includes a command for setting file or directory permissions: chmod. Although this command can be a bit complicated, it is important. The security of your files and subdirectories depends on its proper usage.

The chmod command uses the following syntax:

chmod mode file ...

The complex part of the chmod command is understanding what can go in the mode operand. This is where you specify the owner (also called user), group, and other (everyone else) permissions. You have two ways to do this: numerically and symbolically.

Tip

  • You can learn more about the chmod command by viewing its man pages. In the Terminal window, type man chmod and press .


Numeric permission modes

Numeric permission modes uses numbers to represent permissions options. The best way to explain this is to provide an example. Remember, the nine characters of the permissions coding in a directory listing can be broken down into three sets of three:

rwx

rwx

rwx

user

group

other


Each character can be represented with an octal digit (a number between 0 and 7) by assigning values to the r, w, and x characters, like this:

421

421

421

rwx

rwx

rwx

user

group

other


So, if you want to give read and write permission for a file called file1 to the owner, that would be a 4 (read) plus a 2 (write), which adds up to a 6. You could then give read only permission to the group and others by assigning the value 4 (read). The command to do all this is chmod 644 file1. (The 644 permission is one you'll see often on text files that are readable by everyone. A permission of 600 would make a file private.)

Symbolic permission modes

Symbolic permission modes enables you to add or remove privileges using symbols. For example, to remove write permission from the group and others, type chmod go-w file1. This translates to "take away write permissions from the group and others."

The ownership symbols you use for this are:

u

user (owner) of the file or directory

g

group owner of the file or directory

o

others (everyone)

a

all three (user, group, and others)


The symbols for the permissions you can add or take away are:

r

read

w

write

x

execute


Finally, the operations you can perform are:

+

add the permission

-

remove the permission

=

set (add) the following permissions


You can combine more than one symbol in a mode and more than one "equation" if you separate them with commas. For example, chmod a+;rwx,o-w file1 gives universal read, write, and execute access to all and then takes away write permission from others to file1. (The equivalent numerical permission would be 775.)

To change the permissions for a file or directory

In the Terminal window, type chmod mode file ... (for example, chmod 644 file1) and press .

Warning!

  • Do not change the ownership and permissions of files on your computer with-out reason or if you're not sure what you're doing. The operating system assumes that certain files belong to certain users and have specific privileges. If you change the ownership or permissions on some system files, you may render your computer unusable! It's usually safe to modify your own filesthose that you createbut unless you know what you are doing, stay away from other files.


Tip

  • If you include the -R option in the command (for example, chmod -R 644 folder1), the change is made recursively down through the directory tree. In other words, the change is made to the folder and every file and folder within it.




Visual QuickStart Guide. Mac OS X 10. 4 Tiger
Mac Os X 10.4 Tiger (Visual Quickstart Guides)
ISBN: 0321423372
EAN: 2147483647
Year: 2003
Pages: 301
Authors: Maria Langer

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net