file permissions

go golang linux programming

File Permissions

This diagram was lifted from linuxize

... ls -l commands.go 
-rw-r--r--@ 1 mgemmill  staff  1621  5 Jun 06:56 commands.go
|[-][-][-]|   [------]  [---]
| |  |  | |      |        |
| |  |  | |      |        +------------> 7. Group
| |  |  | |      +---------------------> 6. Owner
| |  |  | +----------------------------> 5. Alternate Access Method
| |  |  +------------------------------> 4. Other Permissions
| |  +---------------------------------> 3. Group Permissions
| +------------------------------------> 2. User  Permissions
+--------------------------------------> 1. File Type 

Numeric view of permissions:

  • r (read) = 4
  • w (write) = 2
  • x (execute) = 1
    • no permission = 0

Go fs.FileMode represents the permission bit on User|Group|Other.

Read, write and execute permission for all three would be:

rwx rwx rwx

Represented as an Octal value:

0777

Read and write permission for just the user and group would be:

rw-rw----

0660