Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Integralist/c61346248e1f6c5c494fec98cb7be75c to your computer and use it in GitHub Desktop.
Save Integralist/c61346248e1f6c5c494fec98cb7be75c to your computer and use it in GitHub Desktop.
[File Permissions with Octal Notation Explanation] #file #permissions #octal

A file can be accessed by different user types:

  • Owner
  • Group
  • Other

Any one of these groups might be allowed to:

  • Read (r)
  • Write (w)
  • Execute (x)

These typically are displayed with a hyphen followed by the permissions for the user type (e.g. -rwx-rwx-rwx):

$ ls -l

-rw-r--r--  1 integralist  staff      2  5 Feb 11:08 foo.txt

Note: in the above example the 'owner' can read/write, while the 'group' and 'other' users can only read the file.

To set these permissions you can use chmod with a 'octal permission' value:

chmod 777 foo.txt

Note: this would mean all user types (owner, group, other) can all read/write/execute the file.

So what do these octal numbers mean?

x (execute) - 1
w (write)   - 2
r (read)    - 4 

We need to combine these numbers for each user type:

To have read and write permissions would require a value of 6 (e.g. 2 (write) + 4 (read) = 6).

If we only wanted the owner to have both read and write, but the others can only read the file, then we'd use:

chmod 644 foo.txt

Because 6 == read/write for owner, while 4 == read for group/other.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment