chmod command can be used with either a text-based
argument or 3 octal digits (see note 1)
to change the permissions on a file.
An example of the text-based command to add "read" permission for group
members and others to a file named
/home/user> ls -l foo -rwx--x--- 1 user user 78 Aug 14 13:08 foo /home/user> chmod go+r foo /home/user> ls -l foo -rwxr-xr-- 1 user user 78 Aug 14 13:08 foo /home/user>
Each permission can be thought of as a single binary digit that is
1"if the permission is granted and "
The nine permissions are naturally grouped into three sets of 3
The first set is the permissions for the owner,
the second set is the permissions for group members,
and the last set is the permissions for others.
Each set of three binary digits can be represented with a single octal
For example, to grant read ("
R") and execute
X") but not write ("
the three binary digits should be
1 0 1.
Looking this up in the chart show that the corresponding octal
Another way to see the same result is to note the weights
shown in the chart for each permission.
By adding up the weights for the permissions you wish to grant,
the octal digit is easily obtained.
For example, to grant read ("
R") and write ("
but not execute ("
X"), you sum the weight for read
4) and write (
2) to get the octal digit
umask command changes an environment setting
that controls which permissions newly created files will have.
This command will never change the permissions of any existing files.
And unless extra steps (not discussed here) are taken, the new setting
will be forgotten as soon as you log off.
To view the current setting, enter the command "
This will report the current setting as a set of three octal digits.
(See note 2.)
To change the setting, enter the command
new_value is three octal digits.
The first digit is the mask for the file owner (or user), the second is the
mask for the group, and the third is the mask for all others.
Each octal digit is expanded to three binary digits, to set the value for
each individual permission bit of the nine permission bits (three groups of
It is important to understand that the
umask setting doesn't
enforce a set of permissions for new files.
Instead it blocks permissions from files.
To complicate matters ever more (if possible), a zero binary digit will
allow that permisison while a one will block that permission.
This is backwards from they way people expect after learning
Consider the following examples:
/home/user> umask 027 /home/user> umask 000 # allow any permissions /home/user> umask 077 # block all permissions for group, others /home/user>
The first example show how to view the current setting, which block
write permission ("
W") for the group and all permissions
The second example doesn't block any permissions, and the last example
blocks all permissions.
Different commands in Unix will create files using a Unix API (a system
The programmer tells
creat what permissions are desired for
the new file.
For example the
vi command attempts to create files with
read and write permissions for all users, whereas the C compiler attemps
to create files with all permissions for all users.
The request permissions will be granted unless blocked by
To understand this better, try setting the
umask value to
000, then create a new file using
Now see what permissions the file has by using the
Try other values and then create new files and see what permissions the
files end up with.
Actually up to four octal digits can be entered. This document does not discuss all the features and the concepts of either permissions or of the chmod and umask commands. (Back)
On some older Unix systems, leading zeros in the numeric output of
commands such as
umask were suppressed.
So an output of
was common to see.