- Chmod
The chmod command (abbreviated from change mode) is a shell command in
Unix andUnix-like environments. When executed, the command can change file system modes of files and directories. The modes includepermissions and special modes.History
A chmod command first appeared in
AT&T Unix version 1, and is still used today on Unix-like machines.Usage
The chmod command options are specified like this:
$ chmod ["options"] "mode" "file1" ...
To view what the permissions currently are, type: $ ls -l "file"
Options
The chmod command has a number of command line options that affect its behavior. The most common options are:
*-R: Changes the modes of directories and files recursively
*-v: Verbose mode; lists all files as they are being processedtring modes
:"See also: Symbolic notation of file system permissions"
To the chmod utility, all permissions and special modes are represented by its mode parameter. One way to adjust the mode of files or directories is to specify a symbolic mode. The symbolic mode is composed of three components, which are combined to form a single string of text:
$ chmod ["references"] ["operator"] ["modes"] "file1" ...
The references (or classes) are used to distinguish the users to whom the permissions apply. If no references are specified it defaults to "all". They are represented by one or more of the following letters:
The combination of these three components produces a string that is understood by the chmod command. Multiple changes can be specified by separating multiple symbolic modes with commas.
tring mode examples
For example, the following command would be used to add the read and write permissions to the user and group classes of a file or directory named sample:
$ chmod ug+rw sample $ ls -ld sample drw-rw---- 2 unixguy unixguy 96 Dec 8 12:53 sample
This command removes all permissions, allowing no one to read, write, or execute the file named sample.
$ chmod a-rwx sample $ ls -l sample ---------- 2 unixguy unixguy 96 Dec 8 12:53 sample
The following command changes the permissions for the user and the group to read and execute only (no write permission) on sample.
Sample file permissions before command $ ls -ld sample drw-rw---- 2 unixguy unixguy 96 Dec 8 12:53 sample $ chmod ug=rx sample $ ls -ld sample dr-xr-x--- 2 unixguy unixguy 96 Dec 8 12:53 sample
Octal numbers
:"See also: Octal notation of file system permissions"
The chmod command also accepts three and four-digit octal numbers representing modes. See the article mentioned above for more information. Using a four-digit octal number to set the modes of a file or directory named sample would look something like this:
$ chmod 0664 sample
Assuming that the setuid, setgid and sticky bits are not set, this is equivalent to:
$ chmod 664 sample
or
$ chmod +r,-x,ug+w sample
pecial modes
:"See also: Additional file system permissions"
The chmod command is also capable of changing the additional permissions or special modes of a file or directory. The symbolic modes use s to represent the "
setuid " and "setgid " modes, and t to represent the "sticky" mode. The modes are only applied to the appropriate classes, regardless of whether or not other classes are specified.Most operating systems support the specification of special modes using octal modes, but some do not. On these systems, only the symbolic modes can be used..
Examples
ee also
*
File system permissions
*chown , the command used to change the owner of a file or directory on Unix-like systems
*chgrp , the command used to change the group of a file or directory on Unix-like systems
*cacls , a command used onWindows NT and its derivatives to modify the access control lists associated with a file or directory
*User ID
*Group ID
*List of Unix programs External links
*man|1|chmod|FreeBSD|change file modes
* [http://www.gnu.org/software/coreutils/manual/html_node/chmod-invocation.html chmod] — manual page fromGNU coreutils .
* [http://www.gnu.org/software/coreutils/manual/html_node/Setting-Permissions.html GNU "Setting Permissions" manual]
* [http://docs.sun.com/app/docs/doc/817-0689/6mgfkpckn?q=chmod&a=view Solaris 9 chmod man page]
* [http://www.hmug.org/man/1/chmod.php Mac OS X chmod man page] , which also supportsaccess control list s.
* [http://neosmart.net/dl.php?id=4 CHMOD-Win 3.0] — Freeware Windows' ACL ←→ CHMOD converter.
* [http://www.classical-webdesigns.co.uk/resources/whatchmod.html What CHMOD? File Permissions Calculator] , web-based CHMOD calculator.
* [http://catcode.com/teachmod/index.html Beginners tutorial with on-line "live" example]
Wikimedia Foundation. 2010.