The `chmod` command is used to adjust file permissions to read, write and execute for the owner, group and others.
chmod is an abbreviation of change mode. A file's mode is the set of permissions attached to it that control access:
Permission settings have different effects on regular files and on directories:
chmod can also set the special permissions setuid, setgid and sticky bit.
chmod commands may be given in symbolic notation:
u = file owner g = file group owner o = everyone else a = all of the above
chmod u+x #give owner only execute permission chmod o-w #remove global write permission chmod g=r #set group permission to read only chmod u+w,go=rx #give owner write permission & set permissions for group and others to read & execute only chmod g+s #add the setgid bit
Octal notation may also be used. An absent digit will be interpreted as a leading zero, so
chmod 1 file is the same as
chmod 0001 file The last three digits refer to the three sections of the mode and act as follows:
1 = x only 2 = w only 3 = w and x 4 = r only 5 = r and x 6 = r and w 7 = r w and x
The first digit applies special permissions:
1 = sticky bit 2 = setgid 4 = setuid
chmod 644 #owner may read and write, group & others only read chmod 755 #owner may read write and execute, group & others read and execute chmod 2750 #setgid, owner may read write and execute, group may read and execute, others have no permissions
The command takes multiple file names as arguments:
chmod 744 foo bar baz #gives the owner rwx and all others r only on the files foo bar and baz
It also has a
-R recursive flag, but it is unusual for files and directories to need the same permissions.