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.