Permissions and Ownership

This document describes three commands to change the permissions and ownership (user or group) for files and directories. For additional information about any of these commands, log onto any COM S Linux/UNIX machine and type man command.

Permissions

Permissions define who can view and make changes to your files and directories. Each file and directory has nine permissions bits, which can be viewed using the -l option to the ls command.

Here is an example:

UNIX> ls -l

-rw-rw-r-- 1 bob undrgrad 0 Apr 20 16:20 file1

-rw------- 1 bob undrgrad 0 Apr 20 16:20 file2

the first column in the example output lists ten permission bits - the first bit describes the type of file. The permissions are of the format "rwxrwxrwx". The first three bits are the owner's permissions, the next three are the group's permissions and the last three are others' (i.e. everyone else's) permissions. The symbols have the following meanings:

Symbol Meaning
r Has permission to read the file/directory.
w Has permission to write to (change) the file/directory.
x Has permission to execute the file (program).

For example, the file file1​ from the example output above may be read and changed by Bob, read and changed by anyone in the undrgrad group, and only read by anyone else. The file file2 may be read and changed only by Bob.

You can change the permissions on a file or directory you own using the chmod command (derived from change mode), as follows: chmod mode filename.

The mode argument is a three-digit octal number describing the permissions for the owner, group and others respectively. Here is a table showing the interpretation of the various digits:

Octal Permissions
0 ---
1 --x
2 -w-
3 -wx
4 r--
5 r-x
6 rw-
7 rwx

Here are come examples:

Command Effect
chmod 644 file2 Allows file2 to be read by anyone, but changed only by Bob.
chmode 600 file1 Allows file1 to by read or changed only by Bob.

The chmod command also accepts a mnemonic syntax for the mode argument. The three categories - owner, group and others - are represented by u, g and o respectively. Permissions can be added, removed or copied by +, - and = respectively. Here are some examples:

Command Effect
chmod u+w Adds write permission for the owner of the file.
chmod ug=rw,o=r Gives read/write permisssion to owner and group and read permission to others.
chmod a-x Removes execute permission for all three categories (owner/group/others).
chmod g=u Makes the group permissions the same as the owner's.
chmod -R g+r mydir Adds read permission for the group to all files in the mydir directory. (The -R stands for "recursive".)

Consult the manual page for additional information about the chmod​ command by running man chmod.

Ownership

To change the owner and/or group of a file or directory, use the chown​ command (derived from change owner). If you only want to change the group for a file or directory, see the corresponding section below.

Here are some examples:

Command Effect
chown bob file1 Makes Bob the owner of file1.
chown bob:undrgrad file1 Makes Bob the owner of file1 and makes the group undrgrad

Group Ownership

To change the group ownershipe of a file use the chgrp command (derived from change group).

Command Effect
chgrp undrgrad file1 Changes the group for file1 to undrgrad.