Chmod
Encyclopedia : C : CH : CHM : Chmod
- The correct title of this } is }}}. The initial letter is capitalized due to [Naming conventions #Lower case first lettertechnical restrictions].
When executed, the command can change file system modes of files and directories. The modes include permissions 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
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 processed
String modes
- See also: Symbolic notation of file system permissions
- classes operator modes
- u (user), which represents the permissions granted to the owner of the file,
- g (group), which represents the users who are members of the file's group, and
- o (others), which represents any users who are not the owner of the file or members of the group, or
- a (all), which represents all three of the above.
- r (read), which grants the ability to read the contents of a file or list a directory's contents,
- w (write), which grants the ability to modify the contents of a file or modify contents in a directory,
- x (execute), which grants the ability to execute a file or recurse a directory tree, and
- X (special execute), which grants the ability to execute similar to execute, but only applies to directories or files that already have the execute permission set so as to allow users to allow traversal of large directory trees.
- +, which adds the specified modes to the specified classes,
- -, which removes the specified modes from the specified classes, and
- =, which means that the modes specified are to be made the exact modes for the specified classes.
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
Octal numbers
- See also: Octal notation of file system permissions
An example of the chmod command using a four-digit octal number to set the modes of a file or directory named sample:
$ chmod 0664 sample
Special modes
- See also: Additional file system permissions
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
- chmod +r file – read is added for all
- chmod -x file – execute permission is removed for all
- chmod u=rw,go= file – read and write is set for the owner, all permissions are cleared for the group and others
- chmod +rw file – change the permissions of the file file to read and write for all.
- chmod -R u+w,go-w docs/ – 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.
- chmod 666 file – read and write access to the owner, the group, and all others.
- chmod 0755 file - Equivalent to u=rwx,go=rx. The 0 specifies no special modes.
- chmod 4755 file - The 4 specifies set user ID.
- find path/ -type d -exec chmod a-x \; - sets a-x for all directories in tree starting from path/ (use '-type f' to match files only).
- chmod -R u+rwX,g-rwx,o-rwx
– Set a directory tree to rwx for owner directories, rw for for owner files, --- for group and all.
See 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 on Windows 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
- [NeoSmart's CHMOD-Win], a freeware application that converts CHMOD commands to settings understood by Windows to help people install web scripts on IIS.
- [FreeBSD chmod man page]
- [GNU chmod manual]
- [Solaris 9 chmod man page]
- [Mac OS X chmod man page], which also supports access control lists.
| Unix command line programs ( ) | |||
| File and file system management: | cat | chdir/cd | chmod | chown | chgrp | cp | du | df | fdupes | file | fsck | ln | ls | lsof | mkdir | more | mount | mv | pwd | rcp | rm | rmdir | split | touch | tree | ||
| Process management: | anacron | at | chroot | cron/crontab | kill | nice | ps | sleep | time | timex | top | renice | wait | ||
| User Management/Environment: | env | finger | id | locale | mesg | passwd | su | sudo | uname | uptime | w | who | write | ||
| Text processing: | awk | cut | diff | ex | head | iconv | join | less | more | nkf | paste | sed | sort | tail | tr | uniq | wc | xargs | ||
| Shell programming: | echo | expr | unset | Printing: | lp |
| Communications: inetd | netstat | ping | rlogin | traceroute | Searching: egrep | fgrep | find | grep | strings | Miscellaneous: banner | bc | cal | man | uname | wall | yes | |
From Wikipedia, the Free Encyclopedia. Original article here. Support Wikipedia by contributing or donating.
All text is available under the terms of the GNU Free Documentation License See Wikipedia Copyrights for details.
