Chmod |
chmod (abbreviated from change mode) is a UNIX shell command in Unix-like environments.
When executed, the command can change file system modes of Computer file and directory. The modes include permissions and special modes.
= History =
A chmod command first appeared in AT&T UNIX version 1.
= Usage =
The chmod command options are specified like this:
chmod switches modes files
= Switches =
chmod has a number of command line options, or switches , that can modify the output. Some of these options are *-R: recursively 0777 *-h: if the file specified is a soft link, change the mode of the link itself rather than the file that the link points to. *-v: verbose. List all files as they are being processed
= Modes =
There are permissions and special modes. The permissions are:
*r - read permission *w - write permission *x - execute permission
Note: A directory requires the execute permission for its contents to be accessible. Also, if the read permission is not set and the execute permission is set for a directory, this allows blind access to files and other directories inside the directory: the contents cannot be listed in entirety, but a specific file or directory can be accessed if the user has prior knowledge of its name.
For each file is specified which permissions apply to the owner of the file, users in the group of the file, or all other users:
*u - owner of the file *g - users in the group of the file *o - all other users
The modes can be specified in two ways, with characters or octal numbers. For characters, there are modification operators. *+ adds the mode *= sets the mode *- removes the mode setting
== Character mode examples ==
*+r read is added for all *-x execute permission is removed for all *u=rw,go= read and write is set for the owner, all permissions are cleared for the group and others
= Octal number values =
Instead of characters, you can use the octal values to set permisions.
In the chmod command you use the combination of 3 numbers, the first number sets the permission for the owner of the file, the second for the group and the last for everybody else.
== Octal examples ==
chmod 766 file.txt This gives full access to the owner and only read and write to others.
chmod 770 file.txt This gives full access to the owner and group and remove access for everybody else.
chmod 635 file.txt This gives read and write access to the owner, write and execute to the group and, execute and read to everyone else.
= Special Modes =
There are three so called special modes as well: the sticky bit, SUID and Setgid.
*1000: If the sticky bit, set by adding octal number 1000 to the permissions, is applied to a directory, then only the file owner, the directory owner, or superuser can delete a file in that directory. For example, if a directory has permissions 0770, then the directory owner or anyone in the directory s group can add files or delete any files (regardless of who the file s owner is). If the sticky bit is set, so the permissions are 1770, then anyone in the group can add files to the directory, but each user can only delete his or her own files.
*2000: This octal permission code sets the Setgid bit. When a directory has this permission, files created within the directory have the group ID of the directory, rather than that of the default group setting for the user who created the file. Note that some operating systems don t allow you to use this numerical value, instead forcing you to use the symbolic alternative.
*4000: This permission sets the set user ID bit. When a directory has this permission, files created within the directory have the user ID of the directory, rather than that of the user who created the file. Note that some operating systems don t allow you to use this numerical value, instead forcing you to use the symbolic alternative.
In octal mode, four numbers are specified and used to set the mode of a file. For owner, group and other the value of each setting is added and the modes are concatenated. The modes are given the values *r 4 (read) *w 2 (write) *x 1 (execute)
Specified as: 0755 - Equivalent to u=rwx,go=rx. The 0 specifies no special modes .
= chmod usage examples =
chmod +rw file.txt The above chmod command will change the permissions of the file file.txt to read and write for all.
chmod -R u+w,go-w docs/ The above chmod command will change the permissions of the directory docs and all its contents to add write access for the user, and deny write access for everybody else.
=See also=
*Chown Unix command to change ownership on a file or directory *Chgrp Unix command to change group on a file or directory *User identifier (Unix) *Group identifier (Unix)
= External links =
*[http://www.neosmart.net/Products/CHMOD-Win.htm NeoSmart s CHMOD-Win], a freeware application that converts CHMOD commands to settings understood by Windows to help people install web scripts on IIS. *[http://www.freebsd.org/cgi/man.cgichmod FreeBSD chmod man page] *[http://www.gnu.org/software/coreutils/manual/html_chapter/coreutils_13.html#SEC81 GNU chmod manual] *[http://docs.sun.com/app/docs/doc/817-0689/6mgfkpcknq=chmod&a=view Solaris 9 chmod man page] *[http://www.hmug.org/man/1/chmod.php Mac OS X chmod man page], which also supports access control lists.|
|