Jump to content
 







Main menu
   


Navigation  



Main page
Contents
Current events
Random article
About Wikipedia
Contact us
Donate
 




Contribute  



Help
Learn to edit
Community portal
Recent changes
Upload file
 








Search  

































Create account

Log in
 









Create account
 Log in
 




Pages for logged out editors learn more  



Contributions
Talk
 



















Contents

   



(Top)
 


1 History  





2 Command syntax  



2.1  Numerical permissions  





2.2  Numeric example  





2.3  Symbolic modes  



2.3.1  Symbolic examples  







2.4  Special modes  





2.5  Command line examples  







3 See also  





4 References  





5 External links  














chmod






العربية
Asturianu
Azərbaycanca
Català
Čeština
Deutsch
Español
Euskara
فارسی
Français

ि
Hrvatski
Italiano
עברית
Lombard
Magyar

Norsk bokmål
Polski
Português
Русский
Slovenščina
کوردی
Suomi
Svenska
ி
Türkçe
Українська
Tiếng Vit

 

Edit links
 









Article
Talk
 

















Read
Edit
View history
 








Tools
   


Actions  



Read
Edit
View history
 




General  



What links here
Related changes
Upload file
Special pages
Permanent link
Page information
Cite this page
Get shortened URL
Download QR code
Wikidata item
 




Print/export  



Download as PDF
Printable version
 




In other projects  



Wikimedia Commons
Wikibooks
 
















Appearance
   

 






From Wikipedia, the free encyclopedia
 


chmod
Original author(s)AT&T Bell Laboratories
Developer(s)Various open-source and commercial developers
Initial release3 November 1971; 52 years ago (1971-11-03)
Written inPlan 9: C
Operating systemUnix, Unix-like, Plan 9, Inferno, IBM i
PlatformCross-platform
TypeCommand
Licensecoreutils: GPLv3
Plan 9: MIT License

InUnix 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,[1] and the name chmod was chosen as an abbreviation of change mode.[2]

History[edit]

Achmod 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[3] 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.[4] 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.[5] The chmod command has also been ported to the IBM i operating system.[6]

Command syntax[edit]

Throughout this section, user refers to the owner of the file, as a reminder that the symbolic form of the command uses "u".

chmod [options] mode[,mode] file1 [file2 ...][7]

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 lsorstat 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 (the first character of the ls 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[edit]

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.

# Sum rwx Permission
7 4(r) + 2(w) + 1(x) rwx read, write and execute
6 4(r) + 2(w) rw- read and write
5 4(r)        + 1(x) r-x read and execute
4 4(r) r-- read only
3        2(w) + 1(x) -wx write and execute
2        2(w) -w- write only
1               1(x) --x execute only
0 0 --- none

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[edit]

Change permissions to permit 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[edit]

The chmod command also accepts a finer-grained symbolic notation,[8] 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 ...

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:

Reference Class Description
u user file owner
g group members of the file's group
o others users who are neither the file's owner nor members of the file's group
a all all three of the above, same as ugo
(empty) default same as "all", except that bits in the umask will be unchanged

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 User, GrouporOthers). It is only really useful when used with + and usually in combination with the -R flag for giving GrouporOthers 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
t sticky

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.[9]

Symbolic examples[edit]

Special modes[edit]

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[edit]

Command Explanation
chmod a+r publicComments.txt Adds read permission for all classes (i.e. user, Group and Others)
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 user, 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 user and Group
chmod 664 global.txt Sets read and write permissions for user and Group, and provides read to Others.
chmod 744 Show_myCV.sh sets read, write, and execute permissions for user, and sets read permission for Group and Others
chmod 1755 findReslts.sh Sets sticky bit (this suggests that the script be retained in memory), sets read, write, and execute permissions for owner, and sets read and execute permissions for group and others
chmod 4755 setCtrls.sh Sets UID, sets read, write, and execute permissions for user, and sets read and execute permissions for Group and Others
chmod 2755 setCtrls.sh sets GID, Sets read, write, and execute permissions for user, and sets read and execute permissions for Group and Others
chmod -R u+rw,g-,o-rx privateStuff Recursively (i.e. on all files and directories in privateStuff) adds read, write permissions for user, 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

See also[edit]

References[edit]

  1. ^ The modes/permissions are shown when listing files in long format.
  • ^ "Tutorial for chmod". catcode.com.
  • ^ "AIX 5.3 System management". IBM knowledge Center. IBM. Retrieved 30 August 2015.
  • ^ "chmod(1): change file mode bits - Linux man page". linux.die.net.
  • ^ "Native Win32 ports of some GNU utilities". unxutils.sourceforge.net.
  • ^ IBM. "IBM System i Version 7.2 Programming Qshell" (PDF). IBM. Retrieved 5 September 2020.
  • ^ "chmod Man Page with examples and calculator - Linux - SS64.com". ss64.com.
  • ^ "AIX 5.5 Commands Reference". IBM Knowledge Center. IBM. Retrieved 30 August 2015.
  • ^ "Permissions masking with umask, chmod, 777 octal permissions". teaching.idallen.com.
  • External links[edit]


    Retrieved from "https://en.wikipedia.org/w/index.php?title=Chmod&oldid=1187389423"

    Categories: 
    File system permissions
    Operating system security
    Standard Unix programs
    Unix file system-related software
    Unix SUS2008 utilities
    Plan 9 commands
    Inferno (operating system) commands
    IBM i Qshell commands
    Hidden categories: 
    Articles with short description
    Short description matches Wikidata
    Use dmy dates from January 2018
     



    This page was last edited on 28 November 2023, at 23:21 (UTC).

    Text is available under the Creative Commons Attribution-ShareAlike License 4.0; 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.



    Privacy policy

    About Wikipedia

    Disclaimers

    Contact Wikipedia

    Code of Conduct

    Developers

    Statistics

    Cookie statement

    Mobile view



    Wikimedia Foundation
    Powered by MediaWiki