How to Read an ls -l Permission String Such as rwxr-xr-x
The first character of an ls -l line is the file type and the next nine are three groups of three: owner, group and others, each showing read, write and execute. Letters other than r, w and x in the execute positions signal the special bits.
At a glance
- Character 1
- File type. - regular, d directory, l symbolic link, c character device, b block device, p named pipe, s socket
- Characters 2 to 4
- Owner: read, write, execute
- Characters 5 to 7
- Group: read, write, execute
- Characters 8 to 10
- Others: read, write, execute
- s or S in position 4
- setuid. Lowercase means execute is also set, uppercase means it is not
- s or S in position 7
- setgid, with the same lowercase and uppercase rule
- t or T in position 10
- Sticky bit, with the same rule against the others execute bit
In detail
The ten character string is the densest thing in a terminal listing and it decodes cleanly once you split it. Take the first character off as the file type, then read the remaining nine in three groups of three. Each group is always read, write, execute in that order, and a dash means the permission is absent. drwxr-xr-x is a directory where the owner has everything and group and others have read and traverse.
The special bits reuse the execute positions rather than adding characters, which is where the confusion starts. An s in the owner execute slot means setuid and execute together. A capital S in the same slot means setuid is set and execute is not, which is almost always an accident: there is nothing to execute, so the bit does nothing.
The same rule applies twice more. Position seven, the group execute slot, shows s or S for setgid, which on a directory is what makes new entries inherit the group. Position ten, the others execute slot, shows t or T for the sticky bit, which on a directory restricts deletion to the entry's owner. /tmp reads as drwxrwxrwt for exactly that reason.
An eleventh character sometimes appears. A trailing plus means the file has an access control list carrying permissions beyond the nine bits, so the string you are reading is not the whole story and getfacl is needed to see the rest. A trailing dot on some systems indicates a security context such as SELinux with no additional ACL.
Going the other way, from a string to an octal number, is three sums of the same three values: read is 4, write is 2, execute is 1. rwx is 7, r-x is 5, rw- is 6, r-- is 4 and --- is 0. The calculator does the conversion in both directions, and its symbolic box takes exactly this nine character form, with the leading type character optional so you can paste a line straight out of a listing.
Examples
-rwxr-xr-x regular file, 755, owner writes, all can run
drwxr-x--- directory, 750, group can list and enter
-rw------- regular file, 600, owner only
lrwxrwxrwx symbolic link, mode is not used for links-rwsr-xr-x 4755 setuid, owner execute also set
-rwSr--r-- 4644 setuid without execute: does nothing
drwxrwsr-x 2775 setgid on a directory: group inheritance
drwxrwxrwt 1777 sticky: restricted deletion, as on /tmp
drwxrwx--T 1770 sticky without others executerwx r-x r-x
421 4-1 4-1
7 5 5 -> 755
rw- r-- ---
42- 4-- ---
6 4 0 -> 640Things that catch people out
- A capital S or T means the special bit is set without the matching execute bit, which is nearly always a mistake rather than a stricter setting.
- The mode shown for a symbolic link is not used for anything. Access is decided by the target's mode, so lrwxrwxrwx is normal and not a problem.
- A trailing plus means an access control list is in play and the nine bits are incomplete. Reading the mode alone will give you the wrong answer about who can do what.
- The nine characters do not tell you who the owner and group actually are. A perfect looking 640 is useless if the group is the owner's private group rather than the service group you intended.
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 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.
chmod 755: The Standard Mode for Directories and Programs
755 gives the owner full control and everyone else read and execute. Why it is right for directories and executables and wrong for ordinary data files.
Four Digit Octal Modes Against Three Digit Ones
The leading digit of a four digit mode carries setuid, setgid and the sticky bit. When 0755 and 755 differ, and what GNU chmod does to directories.
chmod 777: Everyone Gets Everything
777 gives read, write and execute to the owner, the group and everyone else. What it actually allows, why it is never the real fix, and what to use instead.
chmod 775: Owner and Group Write, Everyone Else Reads
775 gives the owner and group full access and leaves others with read and execute. The correct mode for shared directories, and why it needs setgid.
Tools for this
- Chmod Calculator Free online chmod calculator - calculate Unix file permissions with an interactive chmod builder