1. What are Permissions in UNIX?
2. Types of Permissions
There are three main types of permissions:
| Symbol |
Permission |
Applies To Files |
Applies To Directories |
| r |
Read |
View file contents |
List directory contents |
| w |
Write |
Modify file contents |
Add/delete files in directory |
| x |
Execute |
Run the file (if program/script) |
Enter the directory (cd into it) |
3. Viewing Permissions
Use the ls -l command:
ls -l file.txt
Example output:
-rwxr-xr-- 1 user group 1024 Aug 16 10:00 file.txt
Breakdown:
-
- → type (- = file, d = directory).
-
rwx → Owner permissions (read, write, execute).
-
r-x → Group permissions (read, execute).
-
r-- → Others permissions (read only).
So:
-
Owner can read, write, execute.
-
Group can read and execute.
-
Others can only read.
4. Changing Permissions
(a) Using chmod (Change Mode)
Two methods:
-
Symbolic method
chmod u+x file.txt # add execute permission for owner
chmod g-w file.txt # remove write permission from group
chmod o=r file.txt # set others to read-only
-
Numeric method (Octal values)
Examples:
chmod 755 file.txt # rwx for owner, r-x for group, r-x for others
chmod 644 file.txt # rw- for owner, r-- for group, r-- for others
5. Changing Ownership
Examples:
chown alice file.txt # change owner to alice
chgrp developers file.txt # change group to developers
6. Special Permissions (Advanced)
-
Setuid (s) – Run program with file owner’s privileges.
-
Setgid (s) – Files created in a directory inherit the group.
-
Sticky bit (t) – On a directory, only the file’s owner can delete it.
7. Diagram – Permissions in UNIX
+---------------------------+
| PERMISSIONS |
+---------------------------+
| User | Group | Other|
+---------------------------+
| r w x | r w x | r w x|
+---------------------------+
r = read → file: view | directory: list
w = write → file: edit | directory: add/remove
x = execute→ file: run | directory: enter
In summary:
-
UNIX permissions define who can read, write, or execute a file/directory.
-
Controlled via ls -l, chmod, chown, chgrp.
-
Three levels: Owner, Group, Others.
-
Special bits (Setuid, Setgid, Sticky bit) give extra control.