Unix for Mac OS X 10.4 Tiger: Visual QuickPro Guide (2nd Edition)

Setting and Changing Permissions

Although "permissions" means different things for files than for directories, you use the same command to set permissions for both files and directories.

Only the user who owns a file may change its permissions (but see the " sudo the Mac OS X way of using root" section in Chapter 11, on how to use the sudo command to override this limitation).

You use the chmod ( change mode ) command to set the permissions of files.

The general form of a command line for chmod is

chmod mode file

where mode is the permission setting, and file is a filename or even multiple filenames.

The mode argument is in one of two forms: symbolic or absolute .

Symbolic modes are best used to make changes to permissions on a file when you want to alter some of its permissions but leave others unchanged.

Absolute modes are used to set all of the permissions for a file at once.

So if you want to add read permission to a file without disturbing any of the other permissions on the file, you use a symbolic mode. An example of this would be adding read permission to a file for the owning group without changing the permissions for the user or others.

On the other hand, if you want a file to have a specific set of permissions for the user, the group, and others all at once, then you should use an absolute mode. An example of this would be if you wanted to set a file to be readable and writable by the owning user, and only readable by the owning group and others.

Changing permissions with symbolic modes

The basic syntax of a symbolic mode is

who operator what .

For example,

ug+w

would appear in a command line as

chmod ug+w file

The ug are the "who" (user and group), the + is the "operator" (add), and the w is the "what" (write permission). Many combinations are possible. Table 8.1 shows the meanings of each of the characters .

Table 8.1. Symbolic Mode Changes

(T HIS IS A PARTIAL LIST .)

S YMBOLS FOR THE "W HO " P ART

S YMBOL

M EANING

u

Applies change to the owning user.

g

Applies change to the owning group.

o

Applies change to all others.

a

Applies change to all (user, group, and others).

S YMBOLS FOR THE "O PERATOR " P ART

S YMBOL

M EANING

+

Adds the following permissions.

-

Removes the following permissions.

S YMBOLS FOR THE "W HO " P ART

S YMBOL

M EANING

r

Read permission.

w

Write permission.

x

Execute permission.

Here are a few tasks that use symbolic modes to change permissions.

To add read permission to a file for the owning group:

To remove read permission on a file for the owning group:

To add read permission for the group and others:

To add write permission for the group and others:

To remove write permission for the group and others:

Changing permissions with absolute modes

An absolute mode consists of a three- or four-digit number, such as 644 or 2775.

In practice you use these modes in this fashion:

chmod 644 file

That would set the permissions on file to be read and write (6) for the user, and read-only (4) for the group and others.

Most of the time you use three-digit numbers for absolute modes, so we address those first.

Each digit in a three-digit absolute mode represents the permissions for the user, the group, and others, in that order. The value of each digit is based on adding up the values of the kinds of permissions being assigned.

Figure 8.19 shows the values for the absolute modes for each type of permission. Add up the columns to get the modefor instance, for the user to have all permissions, add 4+2+1 to get 7 for the first column; for the group to have read and execute permissions, the value is 4+1, and so on.

Figure 8.19. Diagram showing the values for the absolute modes for each type of permission.

Table 8.2 shows the meanings of each of the eight possible mode values (07) for each digit in an absolute mode. Some of you might be thinking this looks like a base-8 (octal) numbering system. You would be correct.

Table 8.2. Value of Each Digit in a Three-Digit Absolute Mode

V ALUE

M EANING

No permission granted to this owner.

1

Execute permission only.

2

Write permission only.

3

Execute permission and write permission (1 + 2 = 3).

4

Read permission only.

5

Execute and read permission (1 + 4 = 5).

6

Write permission and read permission (2 + 4 = 6).

7

Execute, read, and write permission (1 + 2 + 4 = 7).

To set a file's permissions using absolute mode:

Tip

Категории