Chmod

1

In Unix and Unix-like operating systems, chmod is the command and system call used to change the access permissions and the special mode flags (the setuid, setgid, and sticky flags) of file system objects (files and directories). Collectively these were originally called its ****modes, and the name chmod was chosen as an abbreviation of change mode.

History

A chmod command first appeared in AT&T Unix version 1, along with the chmod system call. As systems grew in number and types of users, access-control lists were added to many file systems in addition to these most basic modes to increase flexibility. The version of chmod bundled in GNU coreutils was written by David MacKenzie and Jim Meyering. The command is available as a separate package for Microsoft Windows as part of the UnxUtils collection of native Win32 ports of common GNU Unix-like utilities. The chmod command has also been ported to the IBM i operating system.

Command syntax

Throughout this section, ser refers to the owner of the file, as a reminder that the symbolic form of the command uses "u", to avoid confusion with "other". Note that only the user or the superuser (root) is able to change file permissions. Usually implemented options include: If a symbolic link is specified, the target object is affected. File modes directly associated with symbolic links themselves are typically not used. To view the file mode, the ls or stat commands may be used: The r, w, and x specify the read, write, and execute access respectively. The first character of the ls -l display denotes the object type; a hyphen represents a plain file. The script findPhoneNumbers.sh can be read, written to, and executed by the user dgerman; read and executed by members of the staff group; and only read by any other users. The main parts of the chmod permissions: For example: rwxr-x--- Each group of three characters define permissions for each class:

Numerical permissions

The chmod numerical format accepts up to four digits. The three rightmost digits define permissions for the file user, the group, and others. The optional leading digit, when 4 digits are given, specifies the special setuid, setgid, and sticky flags. Each digit of the three rightmost digits represents a binary value, which controls the "read", "write" and "execute" permissions respectively. A value of 1 means a class is allowed that action, while a 0 means it is disallowed. For example, 754 would allow: A numerical code permits execution if and only if it is odd (i.e. 1, 3, 5, or 7). A numerical code permits "read" if and only if it is greater than or equal to 4 (i.e. 4, 5, 6, or 7). A numerical code permits "write" if and only if it is 2, 3, 6, or 7.

Numeric example

Change permissions to permit the programmers update of a file: Since the setuid, setgid and sticky bits are not specified, this is equivalent to:

Symbolic modes

The chmod command also accepts a finer-grained symbolic notation, which allows modifying specific modes while leaving other modes untouched. The symbolic mode is composed of three components, which are combined to form a single string of text: Classes of users are used to distinguish to whom the permissions apply. If no classes are specified "all" is implied. The classes 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 removed from the specified classes. There are three basic modes which correspond to the basic permissions: Multiple changes can be specified by separating multiple symbolic modes with commas (without spaces). If a user is not specified, will check the umask and the effect will be as if "a" was specified except bits that are set in the umask are not affected.

Symbolic examples

Special modes

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 numerically, particularly in octal, but some do not. On these systems, only the symbolic modes can be used.

Command line examples

This article is derived from Wikipedia and licensed under CC BY-SA 4.0. View the original article.

Wikipedia® is a registered trademark of the Wikimedia Foundation, Inc.
Bliptext is not affiliated with or endorsed by Wikipedia or the Wikimedia Foundation.

View original