chmod

Change file modes (permissions) for one or more files.

Format

   chmod mode file-list

Summary

The chmod utility displays information about one or more files. It lists the information alphabetically by filename unless you use an option to change the order.

Arguments

The mode specifies the new permissions that you want the file or directory to have. Modes may be absolute or symbolic.

The file-list contains one or more pathnames of files. You can use the pathname of any ordinary, directory, or device file. These pathnames can include ambiguous file references.

Absolute Modes

An absolute mode is an octal (base 8) number constructed from the sum of one or more of the following values:

Value Meaning
400 Allow read by the file's owner.
200 Allow write by the file's owner.
100 For files, allow execution by the file's owner. For directories, allow the owner to search in the directory.
040 Allow read by group members (users who belong to the same group as the file's owner).
020 Allow write by group members.
010 For files, allow execution by group members. For directories, allow group members to search in the directory.
004 Allow read by others (anyone who is not the file's owner and is not in the same group as the file's owner).
002 Allow write by others.
001 For files, allow execution by others. For directories, allow others to search in the directory.

For example, the absolute mode that permits read, write and execute by the owner, read and execute by group members, and read and execute by others is 755 (400+200+100+040+010+004+001). Note that although the numbers being added are in base 8 (octal), the result of the arithmetic is identical to base 10 (decimal).

Symbolic Modes

A symbolic mode is described by the following grammar:

Item Format / Options
mode clause [, clause ...]
clause [who ...] [action ...] action
action op [perm ...]
who a | u | g | o
op + | - | =
perm r | w | x | u | g | o

The who symbols u, g, and o specify the user (owner), group, and other parts of the mode bits, respectively. The who symbol a is equivalent to ugo.

The perm symbols represent the portions of the mode bits as follows:

Symbol Meaning
r The read bits of the mode.
w The write bits of the mode.
x The execute/search bits of the mode.
u The user permission bits in the original mode of the file.
g The group permission bits in the original mode of the file.
o The other permission bits in the original mode of the file.

The op symbols represent the operation performed, as follows:

Symbol Meaning
+ If no value is supplied for perm, the + operation has no effect. If no value is supplied for who, each permission bit specified in perm, for which the corresponding bit in the file mode creation mask is clear, is set. Otherwise, the mode bits represented by the specified who and perm values are set.
- If no value is supplied for perm, the - operation has no effect. If no value is supplied for who, each permission bit specified in perm, for which the corresponding bit in the file mode creation mask is clear, is cleared. Otherwise, the mode bits represented by the specified who and perm values are cleared.
= The mode bits specified by the who value are cleared, or, if no who value is specified, the owner, group and other mode bits are cleared. Then, if no value is supplied for who, each permission bit specified in perm, for which the corresponding bit in the file mode creation mask is clear, is set. Otherwise, the mode bits represented by the specified who and perm values are set.

Examples

The following command grants read, write, and execute permission to the owner of the specified directory and removes those permissions for the group and others.

z123456@turing:~$ chmod 700 csci241

The next command removes execute permission for the owner, group, and others for the file bubble_sort.cpp.

z123456@turing:~/csci241/Assign1$ chmod a-x bubble_sort.cpp

The next command adds execute permission for the owner and removes all permissions for the group and others for the file file1.txt.

z123456@turing:~$ chmod u+x,go-rwx file1.txt