chmod


chmod

Purpose

Change the permission settings of one or more files.

Syntax

chmod [-cfvR] permission files

Options

-c lists only files whose permissions have changed.

-f stops any error message displays.

-v verbosely displays permission changes.

-R recursively changes permissions of files in all subdirectories.

Description

To use chmod effectively, you have to learn how to specify the permission settings. One way is to concatenate one letter from each of the following tables in the order shown (Who/Action/Permission):

Who

Action

Permission

u user

+ add

r read

g group

- remove

w write

o others

= assign

x execute

a all

s set user ID

 

To give everyone read access to all files in a directory, type chmod a+r *. On the other hand, to permit everyone to execute a specific file, type chmod +x filename.

Another way to specify a permission setting is to use a three-digit sequence of octal numbers. In a detailed listing, the read, write, and execute permission settings for the user, group, and others appear as the sequence rwxrwxrwx (with dashes in place of letters for disallowed operations). Think of rwxrwxrwx as three occurrences of the string rwx. Now, assign the values r=4, w=2, and x=1. To get the value of the sequence rwx, simply add the values of r, w, and x. Thus, rwx = 7. Using this formula, you can assign a three-digit value to any permission setting. For example, if the user can read and write the file but everyone else can only read the file, the permission setting is rw-r—r— (that’s how it appears in the listing), and the value is 644. Thus, if you want all files in a directory to be readable by everyone but writable by only the user, use the command chmod 644 *.