home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


UNIX in a Nutshell: System V Edition

UNIX in a Nutshell: System V EditionSearch this book
Previous: Reference: chkey Chapter 2
UNIX Commands
Next: Reference: chown
 

chmod



chmod

 [

option

] 

mode

 

files

Change the access mode of one or more files . Only the owner of a file or a privileged user may change its mode. Create mode by concatenating the characters from who , opcode , and permission . who is optional (if omitted, default is a ); choose only one opcode .

OptionXF

-R

Recursively descend directory arguments while setting modes.

-f

suppress error message upon failure to change a file's mode.

Who

u

User

g

Group

o

Other

a

All (default)

Opcode

+

Add permission

-

Remove permission

=

Assign permission (and remove permission of the unspecified fields)

Permission

r

Read

w

Write

x

Execute

s

Set user (or group) ID

t

Sticky bit; save text (file) mode or prevent removal of files by nonowners (directory)

u

User's present permission

g

Group's present permission

o

Other's present permission

l

Mandatory locking

Alternatively, specify permissions by a 3-digit sequence. The first digit designates owner permission; the second, group permission; and the third, others permission. Permissions are calculated by adding the following octal values:

4

Read

2

Write

1

Execute

Note: A fourth digit may precede this sequence. This digit assigns the following modes:

4

Set user ID on execution

2

Set group ID on execution or set mandatory locking

1

Set sticky bit

Examples

Add execute-by-user permission to file :



chmod u+x 



file

Either of the following will assign read-write-execute permission by owner (7), read-execute permission by group (5), and execute-only permission by others (1) to file :



chmod 751 



file




chmod u=rwx,g=rx,o=x 



file

Any one of the following will assign read-only permission to file for everyone:



chmod =r 



file




chmod 444 



file




chmod a-wx,a+r 



file

Set the user ID, assign read-write-execute permission by owner, and assign read-execute permission by group and others:



chmod 4755 



file


Previous: Reference: chkey UNIX in a Nutshell: System V Edition Next: Reference: chown
Reference: chkey Book Index Reference: chown

The UNIX CD Bookshelf Navigation The UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System