Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Chmod
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== Octal notation === Given a numeric permissions argument, the {{code|chmod}} command treats it as an [[octal]] number, and replaces ''all'' the mode bits for each file. (Although 4 digits are specified, leading {{code|0}} digits can be elided.)<ref>This differs from the βCβ language, where the {{code|0}} prefix for octal numbers is a remnant of its early period.</ref> Why octal rather than decimal? <ref>Although rarely used today, during the early development of UNIX, octal was very useful because repeating groups of 3 bits were common in the physical structure of computers at the time, and these bits were easier to read & understand when encoded as octal digits, just as groups of 4 bits are easier when grouped into hexadecimal digits. The numeric expression of filesystem permissions in octal is one of the few of the few remnants of this time.</ref> There are twelve standard mode bits, comprising 3 special bits ({{Mono|[[setuid]]}}, {{Mono|[[setgid]]}}, and {{Mono|[[Sticky bit|sticky]]}}), and 3 permission groups (controlling access by ''user'', ''group'', and ''other'') of 3 bits each (''read'', ''write'', and ''exec/scan''); each permission bit grants access if set (1) or denies access if clear (0). As an octal digit represents a 3-bit value, the twelve mode bits can be represented as four octal digits. {{code|chmod}} accepts up to four digits and uses 0 for left digits not specified (as is normal for numeric representation). In practice, 3 digits are commonly specified since the special modes are rarely used and the user class is usually specified. In the context of an octal digit, each operation bit represents a numeric value: read: 4, write: 2 and execute: 1. The following table relates octal digit values to a class operations value. {| class="wikitable" |+ Octal digit permission |- ! # !! bits ! rwx ! granted operations |- | 7 | {{Mono|4 + 2 + 1}} | {{code|rwx}} | read, write and execute |- | 6 | {{Mono|4 + 2 }} | {{code|rw-}} | read and write |- | 5 | {{Mono|4 + 1}} | {{code|r-x}} | read and execute |- | 4 | {{Mono|4}} | {{code|r--}} | read only |- | 3 | {{Mono| 2 + 1}} | {{code|-wx}} | write and execute |- | 2 | {{Mono| 2}} | {{code|-w-}} | write only |- | 1 | {{Mono| 1}} | {{code|--x}} | execute only |- | 0 | {{Mono|}} | {{code|---}} | none |} The command [[stat (Unix)|{{code|stat}}]] can report a file's permissions as octal. For example: <syntaxhighlight lang="console"> $ stat -c %a findPhoneNumbers.sh 754 </syntaxhighlight> The reported value, {{code|754}} indicates the following permissions: * user class: read, write, and execute; 7 => (4 + 2 + 1) * group class: read and execute; 5 => (4 + 1) * others class: read only; (4) A code permits execution if and only if it is [[Odd number|odd]] (i.e. 1, 3, 5, or 7). A code permits read if and only if it is greater than or equal to 4 (i.e. 4, 5, 6, or 7). A code permits write if and only if it is 2, 3, 6, or 7.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)