Four Digit Octal Modes Against Three Digit Ones
A three digit octal mode covers owner, group and others. A four digit mode adds a leading digit for the special bits: 4 for setuid, 2 for setgid and 1 for sticky, added together when more than one is set.
At a glance
- Three digit form
- owner, group, others. For example 755
- Four digit form
- special, owner, group, others. For example 0755
- Leading digit values
- 4 setuid, 2 setgid, 1 sticky. Add them: 6 is setuid and setgid, 7 is all three
- 0755 against 755
- Identical on a regular file. 0755 explicitly clears the special bits, 755 leaves them unmentioned
- GNU chmod on directories
- A three digit mode preserves an existing setuid or setgid bit on a directory. A four digit mode sets them explicitly
- Common four digit modes
- 4755 setuid, 2775 setgid, 1777 sticky
- In the calculator
- Both forms are shown for every mode, and the octal box accepts three or four digits
In detail
Every octal mode is really four digits; the leading one is just usually zero and usually omitted. It carries the three special bits, each with its own value: setuid is 4, setgid is 2 and sticky is 1. They add, so 6755 is setuid and setgid together, and 7777 is a mode you should never see outside a demonstration.
For a regular file, 755 and 0755 do the same thing. The difference appears on directories under GNU chmod, which deliberately preserves an existing setuid or setgid bit when you give a three digit mode, so that a routine chmod 755 does not silently break the group inheritance on a shared directory. Writing 0755 states the special bits explicitly and clears them.
That behaviour is worth knowing before you run a recursive chmod across a tree that contains setgid directories. A pass of chmod -R 775 leaves the inheritance intact on GNU systems; a pass of chmod -R 0775 removes it, and the symptom appears later as files arriving with the wrong group again. Other implementations do not all make the same choice, so on a mixed estate be explicit about what you want.
Reading a four digit mode is the reverse of writing one. 4755 splits into 4 and 755: setuid, plus owner read write execute, plus read and execute for group and others. 2770 is setgid with a private shared directory. 1733 is a sticky drop box. The leading digit never affects who can read or write, only how the identity or the deletion rule changes.
The calculator always shows both forms side by side, which is the quickest way to check what a leading digit is doing. Set the three special bit checkboxes and watch the leading digit move through 1, 2, 3, 4, 5, 6 and 7 while the last three digits stay put, and the arithmetic stops being something you have to remember.
Examples
0755 no special bits -rwxr-xr-x
1755 sticky -rwxr-xr-t
2755 setgid -rwxr-sr-x
4755 setuid -rwsr-xr-x
6755 setuid + setgid -rwsr-sr-x
7777 all three, world writable drwsrwsrwt$ ls -ld /srv/project
drwxrwsr-x 2 root developers /srv/project # setgid set
$ chmod 775 /srv/project
drwxrwsr-x # GNU: preserved
$ chmod 0775 /srv/project
drwxrwxr-x # explicitly clearedThings that catch people out
- A recursive three digit chmod can leave setgid directories intact on GNU systems and clear them elsewhere. Be explicit with four digits when the result has to be the same everywhere.
- The leading digit is not a permission. It does not grant read, write or execute to anyone, so a mode like 4644 sets setuid on a file nobody can execute and does nothing at all.
- Reading 2775 as though the 2 belonged to the owner is a common misread. Count from the right: the last three digits are always owner, group and others.
- Four digit modes with a leading 7 turn on all three special bits at once, which is almost never intended and is worth treating as a typo.
Try it: Chmod Calculator
Tick the nine permission boxes, or type an octal or symbolic value, and get the three digit and four digit octal, the ls -l rendering and the exact chmod command back.
Chmod Calculator
LOCAL · Browser-OnlyCalculate Unix file permissions with an interactive chmod builder
Permission Matrix
| Entity | Read (4) | Write (2) | Execute (1) | Octal | Symbolic |
|---|---|---|---|---|---|
| Owner (u) | 7 | rwx | |||
| Group (g) | 5 | r-x | |||
| Others (o) | 5 | r-x |
Special Bits
Advanced permission flags for executables and directories
Generated Permissions
755rwxr-xr-x-rwxr-xr-xchmod 755 filenamechmod u=rwx,g=rx,o=rx filenamePermission Breakdown
Owner (u)
7rwx- - Read files / list directory contents
- - Write / modify / delete
- - Execute / traverse directory
Group (g)
5r-x- - Read files / list directory contents
- - Execute / traverse directory
Others (o)
5r-x- - Read files / list directory contents
- - Execute / traverse directory
Common Permissions Reference
| Octal | Symbolic | Meaning |
|---|---|---|
777 | rwxrwxrwx | Full access for everyone |
755 | rwxr-xr-x | Owner full, others read and execute |
750 | rwxr-x--- | Owner full, group read and execute |
700 | rwx------ | Owner full access only |
666 | rw-rw-rw- | Read and write for everyone |
644 | rw-r--r-- | Owner read/write, others read only |
600 | rw------- | Owner read/write only |
555 | r-xr-xr-x | Read and execute for everyone |
444 | r--r--r-- | Read only for everyone |
400 | r-------- | Owner read only |
Related File permissions
All file permissions →chmod 4755: The setuid Bit and What It Actually Does
4755 sets the setuid bit on top of 755, so the program runs as its owner instead of as the caller. Where it is required and why it is dangerous.
chmod 2775: The setgid Bit on Directories and on Files
2775 adds the setgid bit to 775 so new files inherit the directory's group. The fix for shared directories where the team cannot edit each other's files.
chmod 1777: The Sticky Bit and Why /tmp Needs It
1777 adds the sticky bit to a world writable directory so only a file's owner can delete it. The mode of /tmp and the fix for any shared drop directory.
Symbolic chmod Notation: u, g, o, a With Plus, Minus and Equals
Symbolic mode changes one class at a time instead of setting all nine bits. How plus, minus and equals differ, and what the capital X form is for.
Recursive chmod and Why 755 Across a Source Tree Is Wrong
chmod -R applies one mode to files and directories alike, which is almost never what you want. The find and capital X patterns that do the job properly.
chmod +x: Making a File Executable and the umask Catch
chmod +x adds the execute bit, but without a class it is masked by the umask. Why scripts also need read, and how to record the bit in version control.
Tools for this
- Chmod Calculator Free online chmod calculator - calculate Unix file permissions with an interactive chmod builder