Solaris Advanced User's Guide

Setting Absolute Permissions

In the previous section, you used the chmod command to change file permissions relative to their current settings. You can also set the permissions for a file or directory absolutely by using numeric codes with the chmod command.

The syntax for this usage of the chmod command is:

chmod numcode name

In this example, numcode is the numeric code and name is the name of the file or directory for which you are changing permissions.

The complete numeric code consists of three numbers. One number is used for each of the three categories: user, group, and others. For example, the following command sets absolute read, write, and execute permissions for the user and the group, and execute permissions only for others.


$ chmod 771 garlic

Table 3–2 illustrates how the the code 771 describes the permissions for garlic.

Table 3–2 Permissions for garlic

Permission 

User 

Group 

Others 

Read 

Write 

Execute 

Total 

Each of the columns in Table 3–2 represents one of the categories: user, group, and others. To set read permissions, add 4 to the appropriate column. To set write permissions, add 2. To add execute permissions, add 1. The total in all three columns in the last row of the table is the complete numeric code.

The following is another example of using numeric codes to set absolute permissions, with the inclusion of the ls -l command to demonstrate the results.


$ ls -l onions
-rwxr-xr-x   1 user2    users      65536 Nov  1 09:18 onions
$ chmod 755 onions
$ ls -l onions
-rwxr-xr-x   1 user2    users      65536 Nov  1 09:18 onions
$

The chmod 755 onions command sets the permissions for the file onions so that the user can read, write, and execute, group members can read and execute, and others can read and execute. Table 3–3 describes the numeric code that is used to set the permissions for onions.

Table 3–3 Permissions for onions

Permission 

User 

Group 

Others 

Read 

Write 

Execute 

Total 

To provide read, write, and execute permissions for the file cabbage to yourself, your group, and all other users, type the following command.


$ ls -l cabbage
-rw-r--r--   1 user2    users         75 Nov  1 09:28 cabbage
$ chmod 777 cabbage
$ ls -l cabbage
-rwxrwxrwx   1 user2    users         75 Nov  1 09:28 cabbage
$

Table 3–4 describes the numeric code that is used to set permissions in the previous example.

Table 3–4 Permissions for cabbage

Permission 

User 

Group 

Others 

Read 

Write 

Execute 

Total 

The numeric code 777 represents the maximum level of permissions you can provide.

Similar to changing relative permissions, you can also use the wildcard character * to set absolute permissions for all in the files in the current directory. For example, suppose you want to set absolute permissions for all files in the current directory as follows:

To set these permissions, type the following commands.


$ pwd
/home/user2/veggies
$ ls -l
-rwxrwxrwx   1 user2    users       5618 Nov  1 09:18 beets
-rwxrwxrwx   1 user2    users       1777 Nov  1 09:18 corn
-rwxrwxrwx   1 user2    users       3424 Nov  1 09:18 garlic
-rwxrwxrwx   1 user2    users      65536 Nov  1 09:18 onions
$ chmod 751 *
$ ls -l
-rwxr-x--x   1 user2    users       5618 Nov  1 09:18 beets
-rwxr-x--x   1 user2    users       1777 Nov  1 09:18 corn
-rwxr-x--x   1 user2    users       3424 Nov  1 09:18 garlic
-rwxr-x--x   1 user2    users      65536 Nov  1 09:18 onions
$

The pwd command is included in this example to illustrate that the directory on which you perform this operation must be the current directory. The ls -l command is shown only to illustrate the changes in permissions. When setting absolute permissions, you do not need to know what the permissions are currently.

For more information on the chmod(1) command, refer to the man Pages(1): User Commands.