Chmod - wikipedia Chmod In Unix - like operating systems, chmod is the command and system call which may change the access permissions to file system objects ( files and directories ). It may also alter special mode flags. The request is filtered by the umask. The name is an abbreviation of change mode. Contents 1 History 2 Command syntax 2.1 Octal modes 2.1. 1 Numeric example 2.2 Symbolic modes 2.2. 1 Symbolic examples 2.3 Special modes 2.4 Command line examples 3 System call 4 See also 5 References 6 External links History A chmod command first appeared in AT&T Unix version 1. 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. Command syntax chmod ( options ) mode (, mode ) file1 ( file2... ) Usual implemented options include : - R recursive, i.e. include objects in subdirectories - f force, forge ahead with all objects even if errors occur - v verbose, show objects processed If a symbolic link is specified, the target object is affected. File modes directly associated with symbolic links themselves are typically never used. To view the file mode, the ls or stat commands may be used : $ ls - l findPhoneNumbers.sh - rwxr - xr -- 1 dgerman staff 823 Dec 16 15 : 03 findPhoneNumbers.sh $ stat - c % a findPhoneNumbers.sh 754 The r, w, and x specify the read, write, and execute access, respectively. The first character of the ls display denotes the object type ; a hyphen represents a plain file. This script can be read, written to, and executed by the owner, read and executed by other members of the staff group and can also be read by others. Octal modes See also : Octal notation of file system permissions The main parts of the chmod permissions : Example : drwxrwx -- - To the right of the `` d '' : the left three characters rwx define permissions of the OWNER. the middle three characters rwx define permissions of the GROUP. the right three characters -- - define permissions of EVERYONE ELSE. In this example EVERYONE ELSE has no permissions. The chmod numerical format accepts up to four octal digits. The three rightmost digits refer to permissions for the file owner, the group, and other users. The optional leading digit, when 4 digits are given, specifies the special setuid, setgid, and sticky flags. Numerical permissions # Permission rwx 7 read, write and execute rwx 6 read and write rw - 5 read and execute r-x read only r -- write and execute - wx write only - w - execute only -- x 0 none -- - Numeric example In order to permit all users who are members of the programmers group to update a file $ ls - l sharedFile - rw - r -- r -- 1 jsmith programmers 57 Jul 3 10 : 13 sharedFile $ chmod 664 sharedFile $ ls - l sharedFile - rw - rw - r -- 1 jsmith programmers 57 Jul 3 10 : 13 sharedFile Since the setuid, setgid and sticky bits are not specified, this is equivalent to : $ chmod 0664 sharedFile Symbolic modes See also : Symbolic notation of file system permissions 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 : $ chmod ( references ) ( operator ) ( modes ) file... The references ( or classes ) are used to distinguish the users to whom the permissions apply. If no references are specified it defaults to `` all '' but modifies only the permissions allowed by the umask. The references are represented by one or more of the following letters : Reference Class Description u owner file 's owner g group users who are members of the file 's group o others users who are neither the file 's owner nor members of the file 's group all all three of the above, 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 removed 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 one execute permission bit already set ( either owner, 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 sticky details in Special modes section Multiple changes can be specified by separating multiple symbolic modes with commas ( without spaces ). If a user is not specified, chmod 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 Add write permission ( w ) to the group 's ( g ) access modes of a directory, allowing users in the same group to add files : $ ls - ld shared_dir # show access modes before chmod drwxr - xr - x 2 teamleader usguys 96 Apr 8 12 : 53 shared_dir $ chmod g + w shared_dir $ ls - ld shared_dir # show access modes after chmod drwxrwxr - x 2 teamleader usguys 96 Apr 8 12 : 53 shared_dir Remove write permissions ( w ) for all classes ( a ), preventing anyone from writing to the file : $ ls - l ourBestReferenceFile - rw - rw - r -- 2 teamleader usguys 96 Apr 8 12 : 53 ourBestReferenceFile $ chmod a-w ourBestReferenceFile $ ls - l ourBestReferenceFile - r -- r -- r -- 2 teamleader usguys 96 Apr 8 12 : 53 ourBestReferenceFile Set the permissions for the owner and the group ( ug ) to read and execute ( rx ) only ( no write permission ) on referenceLib, preventing anyone to add files. $ ls - ld referenceLib drwxr -- -- - 2 teamleader usguys 96 Apr 8 12 : 53 referenceLib $ chmod ug = rx referenceLib $ ls - ld referenceLib dr - xr - x -- - 2 teamleader usguys 96 Apr 8 12 : 53 referenceLib Special modes See also : 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. Command line examples Command Explanation chmod a + r publicComments. txt adds read permission for all classes ( i.e. owner, group and others ) chmod + r publicComments. txt adds read permission for all classes depending on umask chmod a-x publicComments. txt removes execute permission for all classes chmod a + rx viewer.sh adds read and execute permissions for all classes chmod u = rw, g = r, o = internalPlan. txt sets read and write permission for owner, sets read for group, and denies access for others chmod - R u + w, go - w docs adds write permission to the directory docs and all its contents ( i.e. Recursively ) for owner, and removes write permission for group and others chmod ug = rw groupAgreements. txt sets read and write permissions for owner and group chmod 664 global. txt sets read and write permissions for owner and group, and provides read to others. chmod 0744 myCV. txt sets read, write, and execute permissions for owner, and sets read permission for group and others ( the 0 specifies no special modes ) chmod 1755 findReslts.sh sets sticky bit, sets read, write, and execute permissions for owner, and sets read and execute permissions for group and others ( this suggests that the script be retained in memory ) chmod 4755 setCtrls.sh sets UID, sets read, write, and execute permissions for owner, and sets read and execute permissions for group and others chmod 2755 setCtrls.sh sets GID, sets read, write, and execute permissions for owner, and sets read and execute permissions for group and others chmod - R u + rwX, g - rwx, o - rx personalStuff Recursively ( i.e. on all files and directories in personalStuff ) adds read, write, and special execution permissions for owner, removes read, write, and execution permissions for group, and removes read and execution permissions for others chmod - R a-x + X publicDocs Recursively ( i.e. on all files and directories in publicDocs ) removes execute permission for all classes and adds special execution permission for all classes System call The POSIX standard defines the following function prototype : int chmod ( const char * path, mode_t mode ) ; The mode parameter is a bitfield composed of various flags : Flag Octal value Purpose S_ISUID 04000 Set user ID on execution S_ISGID 02000 Set group ID on execution S_ISVTX 01000 Sticky bit S_IRUSR, S_IREAD 00400 Read by owner S_IWUSR, S_IWRITE 00200 Write by owner S_IXUSR, S_IEXEC 00100 Execute / search by owner S_IRGRP 00040 Read by group S_IWGRP 00020 Write by group S_IXGRP 00010 Execute / search by group S_IROTH 00004 Read by others S_IWOTH 00002 Write by others S_IXOTH 00001 Execute / search by others See also File system permissions Modes ( Unix ) chattr, the command used to change the attributes of a file or directory on Linux systems 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 attrib umask, restricts mode ( permissions ) at file or directory creation on Unix - like systems User identifier Group identifier List of Unix programs References Jump up ^ Tutorial for chmod Jump up ^ `` AIX 5.3 System management ''. IBM knowledge Center. IBM. Retrieved 30 August 2015. Jump up ^ chmod Jump up ^ `` AIX 5.5 Commands Reference ''. IBM Knowledge Center. IBM. Retrieved 30 August 2015. Jump up ^ http://teaching.idallen.com/cst8207/12f/notes/510_umask.html Jump up ^ `` chmod function ''. The Open Group Base Specifications Issue 7, 2013 Edition. The Open Group. Retrieved 30 August 2015. External links chmod ( 1 ) : change file modes -- FreeBSD General Commands Manual chmod ( 1 ) -- Plan 9 Programmer 's Manual, Volume 1 chmod -- manual page from GNU coreutils. GNU `` Setting Permissions '' manual CHMOD - Win 3.0 -- Freeware Windows ' ACL ← → CHMOD converter. Beginners tutorial with on - line `` live '' example Unix command - line interface programs and shell builtins File system cat chmod chown chgrp cksum cmp cp dd du df file fuser ln ls mkdir mv pax pwd rm rmdir split tee touch type umask Processes at bg crontab fg kill nice ps time User environment env exit logname mesg talk tput uname who write Text processing awk basename comm csplit cut diff dirname ed ex fold head iconv join m4 more nl paste printf sed sort strings tail tr uniq vi wc xargs Shell builtins alias cd echo test unset wait Searching find grep Documentation man Software development ar ctags lex make nm strip yacc Miscellaneous bc cal expr lp od sleep true and false Categories Standard Unix programs Unix SUS2008 utilities List Retrieved from `` https://en.wikipedia.org/w/index.php?title=Chmod&oldid=818748073 '' Categories : File system permissions Operating system security Standard Unix programs Unix file system - related software Unix SUS2008 utilities Hidden categories : Use dmy dates from January 2018 Talk Contents About Wikipedia Wikibooks Asturianu Azərbaycanca Català Čeština Deutsch Español Euskara فارسی Français 한국어 हिन्दी Hrvatski Italiano Lumbaart Magyar 日本 語 Norsk Polski Português Русский Slovenščina کوردی Suomi Svenska தமிழ் Українська Tiếng Việt 中文 Edit links This page was last edited on 5 January 2018, at 09 : 53. Text is available under the Creative Commons Attribution - ShareAlike License ; additional terms may apply. By using this site, you agree to the Terms of Use and Privacy Policy. Wikipedia ® is a registered trademark of the Wikimedia Foundation, Inc., a non-profit organization. About Wikipedia

Question: how to change permission to a file in unix
Answer: chmod is the command and system call