OpenWindows Advanced User's Guide

3.6.4 Setting Absolute Permissions

Up to this point, the discussion on permissions has only included using the chmod command to change permissions relative to their current settings. Using a different form of the chmod command, which applies numeric codes to specify permissions, you can set the permissions for a file or directory absolutely.

The syntax for this usage of the chmod command is:

chmod numcode name

where 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-1 illustrates how the permissions described for garlic are represented by the code 771.

Table 3-1 Permissions for garlic

Permission 

User 

Group 

Others 

Read 

Write 

Execute 

Total 

Each of the columns in Table 3-1 represents one of the categories: user, group, and others. To set read permissions, you add 4 to the appropriate column. To set write permissions, you add 2. To add execute permissions, you 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 this method for setting absolute permissions, with the ls -l command included to demonstrate the results:

$ ls -l onion
-rw-r--r--  3 user2           1024 Feb 10 11:46 onion
$ chmod 755 onion
$ ls -l onion
-rwxr-xr-x  3 user2           1024 Feb 10 11:48 onion
$

The permissions for the file onion are set so that the user can read, write, and execute; group members can read and execute; and others can also read and execute. Table 3-2 provides the breakdown of the numeric code used to set the permissions for onion.

Table 3-2 Permissions for onion

Permission 

User 

Group 

Others 

Read 

Write 

Execute 

Total 

Of course, to provide read, write, and execute permissions for the file cabbage to yourself, your group, and all other users, you would enter the following:

$ ls -l cabbage
-rw-r--r--  3 user2           1024 Feb 10 11:51 cabbage
$ chmod 777 cabbage
$ ls -l cabbage
-rwxrwxrwx  3 user2           1024 Feb 10 11:53 cabbage
$

Table 3-3 provides the breakdown for this example.

Table 3-3 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, to set absolute permissions for all files in the current directory veggies so that you have read, write, and execute permissions; your group has read and execute permissions; and all other users have execute permissions only, you would enter the following:

$ pwd
/home/user2/veggies
$ ls -l
-rwxrwxrwx  3 user2          21032 Feb 12 10:31 beats
-rwxrwxrwx  2 user2             68 Feb 10 11:09 corn
-rwxrwxrwx  3 user2          12675 Feb 08 09:31 garlic
-rwxrwxrwx  1 user2           1024 Feb 14 16:38 onions
$ chmod 751 *
$ ls -l
-rwxr-x--x  3 user2          21032 Feb 12 10:31 beats
-rwxr-x--x  2 user2             68 Feb 10 11:09 corn
-rwxr-x--x  3 user2          12675 Feb 08 09:31 garlic
-rwxr-x--x  1 user2           1024 Feb 14 16:38 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, it's not necessary to know what the permissions are currently.

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