Information about Chmod
The chmod command (abbreviated from change mode) is a shell command in Unix and Unix-like environments.
When executed, the command can change file system modes of files and directories. The modes include permissions and special modes.
$ chmod [options] mode file1 ...
To view what the permissions currently are, type:
$ ls -l
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 chmod program uses an operator to specify how the modes of a file should be adjusted. The following operators are accepted:
The modes indicate which permissions are to be granted or taken away from the specified classes. There are three basic modes which correspond to the basic permissions:
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.
$ chmod ug+rw sample $ ls -ld sample drw-rw
2 unixguy unixguy 96 Dec 8 12:53 sample
This command removes all permissions, and allows 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
The chmod command also accepts three- and four-digit octal numbers representing modes. See the article mentioned above for more. 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
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.
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
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:
| Reference | Class | Description |
|---|---|---|
| u | user | the owner of the file |
| g | group | users who are members of the file's group |
| o | others | users who are not the owner of the file or members of the group |
| a | all | all three of the above, is the same as ugo |
The chmod program uses an operator to specify how the modes of a file should be adjusted. The following operators are accepted:
| Operator | Description |
|---|---|
| + | adds the specified modes to the specified classes |
| - | removes the specified modes from the specified classes |
| = | the modes specified are to be made the exact modes for the specified classes |
The modes indicate which permissions are to be granted or taken away from the specified classes. There are three basic modes which correspond to the basic permissions:
| Mode | Name | Description |
|---|---|---|
| r | read | read a file or list a directory's contents |
| w | write | write to a file or directory |
| x | execute | execute a file or recurse a directory tree |
| X | special execute | which is not a permission in itself but rather can be used instead of x. It applies execute permissions to directories regardless of their current permissions and applies execute permissions to a file which already has at least 1 execute permission bit already set (either user, group or other). It is only really useful when used with '+' and usually in combination with the -R option for giving group or other access to a big directory tree without setting execute permission on normal files (such as text files), which would normally happen if you just used "chmod -R a+rx .", whereas with 'X' you can do "chmod -R a+rX ." instead |
| s | setuid/gid | details in Special modes section |
| t | sticky | details in Special modes section |
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.
String 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, and allows 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. 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
Special 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
- 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 – removes read and write access for the owner, the group, and all others.
- chmod 0755 file – equivalent to u=rwx (4+2+1),go=rx (4+1 & 4+1). 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).
- find path/ -type d -exec chmod 777 {} \; allows directory browsing ls for example if you've reset permissions for Samba write access.
- chmod -R u+rwX,g-rwx,o-rwx <directory> – set a directory tree to rwx for owner directories, rw 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
- : FreeBSD General Commands Manual
- GNU chmod manual
- GNU "Setting Permissions" manual
- Solaris 9 chmod man page
- Mac OS X chmod man page, which also supports access control lists.
- CHMOD-Win 3.0 — Freeware Windows' ACL ←→ CHMOD converter.
- What CHMOD? File Permissions Calculator, web-based CHMOD calculator.
Unix command line programs and builtins (more) | |
|---|---|
| File and file system management | cat chattr cd chmod chown chgrp cksum cmp cp du df file fsck fuser ln ls lsof mkdir mount mv pwd rm rmdir split touch |
| Process management | at chroot crontab exit kill killall nice pgrep pidof pkill ps sleep time top wait watch |
| User Management/Environment | env finger id logname mesg passwd su sudo uname uptime w wall who whoami write |
| Text processing | awk comm cut ed ex fmt head iconv join less more paste sed sort tac tail tr uniq wc xargs |
| Shell programming | basename echo expr false printf test true unset |
| Printing: lp Communications: inetd netstat ping rlogin nc traceroute Searching: find grep strings Miscellaneous: banner bc cal dd man size yes | |
Unix shell, also called "the command line", provides the traditional user interface for the Unix operating system and for Unix-like systems. Users direct the operation of the computer by entering command input as text for a shell to execute.
..... Click the link for more information.
..... Click the link for more information.
Unix (officially trademarked as UNIX®) is a computer operating system originally developed in 1969 by a group of AT&T employees at Bell Labs including Ken Thompson, Dennis Ritchie and Douglas McIlroy.
..... Click the link for more information.
..... Click the link for more information.
Unix-like operating system is one that behaves in a manner similar to a Unix system, while not necessarily conforming to or being certified to any version of the Single UNIX Specification.
..... Click the link for more information.
..... Click the link for more information.
computer file is a block of arbitrary information, or resource for storing information, which is available to a computer program and is usually based on some kind of durable storage.
..... Click the link for more information.
..... Click the link for more information.
In computing, a directory, catalog, or folder[1] is an entity in a file system which contains a group of files and/or other directories. A typical file system may contain thousands (or even hundreds of thousands) of directories.
..... Click the link for more information.
..... Click the link for more information.
Most modern file systems have methods of administering permissions or access rights to specific users and groups of users. These systems control the ability of the users affected to view or make changes to the contents of the file system.
..... Click the link for more information.
..... Click the link for more information.
AT&T Inc.
Public (NYSE: T )
Founded 1983[1]
Headquarters San Antonio, Texas, USA
Key people Randall L. Stephenson, Chairman/CEO; Richard Lindner, CFO
Industry Telecommunications
Products Wireless, Telephone, Internet, Television
..... Click the link for more information.
Public (NYSE: T )
Founded 1983[1]
Headquarters San Antonio, Texas, USA
Key people Randall L. Stephenson, Chairman/CEO; Richard Lindner, CFO
Industry Telecommunications
Products Wireless, Telephone, Internet, Television
..... Click the link for more information.
Unix (officially trademarked as UNIX®) is a computer operating system originally developed in 1969 by a group of AT&T employees at Bell Labs including Ken Thompson, Dennis Ritchie and Douglas McIlroy.
..... Click the link for more information.
..... Click the link for more information.
Recursion, in mathematics and computer science, is a method of defining functions in which the function being defined is applied within its own definition. The term is also used more generally to describe a process of repeating objects in a self-similar way.
..... Click the link for more information.
..... Click the link for more information.
setuid and setgid are Unix terms, which are short for "Set User ID" and "Set Group ID", respectively. setuid (also sometimes referred to as "suid") and setgid are access right flags that can be assigned to files and directories in a Unix system.
..... Click the link for more information.
..... Click the link for more information.
setuid and setgid are Unix terms, which are short for "Set User ID" and "Set Group ID", respectively. setuid (also sometimes referred to as "suid") and setgid are access right flags that can be assigned to files and directories in a Unix system.
..... Click the link for more information.
..... Click the link for more information.
The sticky bit is an access-right flag that can be assigned to files and directories on Unix systems.
..... Click the link for more information.
History
The sticky bit was introduced in the Fifth Edition of Unix in 1974 for use with pure executable files...... Click the link for more information.
setuid and setgid are Unix terms, which are short for "Set User ID" and "Set Group ID", respectively. setuid (also sometimes referred to as "suid") and setgid are access right flags that can be assigned to files and directories in a Unix system.
..... Click the link for more information.
..... Click the link for more information.
Most modern file systems have methods of administering permissions or access rights to specific users and groups of users. These systems control the ability of the users affected to view or make changes to the contents of the file system.
..... Click the link for more information.
..... Click the link for more information.
The chown command is used on Unix-like systems to change the owner of a file. In most implementations, it can only be executed by the Superuser. Unprivileged (regular) users who wish to change the group of a file that they own may use chgrp.
..... Click the link for more information.
..... Click the link for more information.
The chgrp command is used by unprivileged users on Unix-like systems to change the group associated with a file. Unlike the chown command, chgrp allows regular users to change groups, but only to one of which they are a member.
..... Click the link for more information.
..... Click the link for more information.
Cacls.exe (Change Access Control Lists) is an executable in Microsoft Windows to change Access Control List (ACL) permissions on a directory, its subcontents, or files. An access control list is a list of permissions for a file or directory that controls who can access it.
..... Click the link for more information.
..... Click the link for more information.
Windows NT
Company/developer: Microsoft
Source model: Closed source / Shared source
Stable release: +/-
Preview release:
..... Click the link for more information.
Company/developer: Microsoft
Source model: Closed source / Shared source
Stable release: +/-
Preview release:
..... Click the link for more information.
On Unix-like systems, users are represented by a user identifier, often abbreviated UID. The range of values for a UID varies amongst different systems; at the very least, a UID can be between 0 and 32767, with some restrictions:
..... Click the link for more information.
..... Click the link for more information.
group identifier, often abbreviated to GID, is a numeric value used to represent a specific group. The range of values for a GID varies amongst different systems; at the very least, a GID can be between 0 and 32767, with one restriction: the login group for the Superuser
..... Click the link for more information.
..... Click the link for more information.
Printing: lp Communications: inetd netstat ping rlogin nc traceroute Searching: find grep strings Miscellaneous: banner bc cal dd man size yes
..... Click the link for more information.
..... Click the link for more information.
FreeBSD is a Unix-like free operating system descended from AT&T UNIX via the Berkeley Software Distribution (BSD) branch through the 386BSD and 4.4BSD operating systems.
..... Click the link for more information.
..... Click the link for more information.
man pages (short for "manual pages"). The Unix command used to display them is man. Each page is a self-contained document.
man <page_name>
at a shell prompt, for example, "
..... Click the link for more information.
Usage
To read a page from the manual, one can use the commandman <page_name>
at a shell prompt, for example, "
..... Click the link for more information.
In computer security, an access control list (ACL) is a list of permissions attached to an object. The list specifies who or what is allowed to access the object and what operations are allowed to be performed on the object.
..... Click the link for more information.
..... Click the link for more information.
Unix (officially trademarked as UNIX®) is a computer operating system originally developed in 1969 by a group of AT&T employees at Bell Labs including Ken Thompson, Dennis Ritchie and Douglas McIlroy.
..... Click the link for more information.
..... Click the link for more information.
command line interface or CLI is a method of interacting with an operating system or software using a command line interpreter. This command line interpreter may be a text terminal, terminal emulator, or remote shell client such as PuTTY.
..... Click the link for more information.
..... Click the link for more information.
Printing: lp Communications: inetd netstat ping rlogin nc traceroute Searching: find grep strings Miscellaneous: banner bc cal dd man size yes
..... Click the link for more information.
..... Click the link for more information.
The cat command is a standard Unix program used to concatenate and display files. The name is from , a synonym of concatenate.
..... Click the link for more information.
Specification
The Single Unix Specification specifies the behavior that each of the files given in sequence as arguments will write their..... Click the link for more information.
chattr is a UNIX program that allows a user to set certain attributes to a file. Mostly chattr is used to make files immutable so that password files and certain system files cannot be erased during software upgrades.
..... Click the link for more information.
..... Click the link for more information.
cd, sometimes also available as chdir (change directory), is a command line command to change the current working directory in operating systems such as Unix, Windows and DOS.
..... Click the link for more information.
..... Click the link for more information.
This article is copied from an article on Wikipedia.org - the free encyclopedia created and edited by online user community. The text was not checked or edited by anyone on our staff. Although the vast majority of the wikipedia encyclopedia articles provide accurate and timely information please do not assume the accuracy of any particular article. This article is distributed under the terms of GNU Free Documentation License.
Herod_Archelaus