From e33f979844e33ef0e316e8759caef4fc958d210e Mon Sep 17 00:00:00 2001 From: Tharindu Lakshan Date: Wed, 6 Aug 2025 00:01:44 +0530 Subject: [PATCH 1/2] add file-permissions.md --- .../file-permissions.md | 101 ++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 Week 1 - Linux Fundamentals/03_Users_and_Permissions/file-permissions.md diff --git a/Week 1 - Linux Fundamentals/03_Users_and_Permissions/file-permissions.md b/Week 1 - Linux Fundamentals/03_Users_and_Permissions/file-permissions.md new file mode 100644 index 0000000..62b1936 --- /dev/null +++ b/Week 1 - Linux Fundamentals/03_Users_and_Permissions/file-permissions.md @@ -0,0 +1,101 @@ +# ๐Ÿ“ File Permissions in Linux + +File permissions help control **who** can read, write, or execute a file or directory. + +## ๐Ÿ” Symbolic Permissions + +User types: + +- `u` โ†’ **user** (owner) +- `g` โ†’ **group** +- `o` โ†’ **others** + +Permissions: + +- `r` โ†’ **read** +- `w` โ†’ **write** +- `x` โ†’ **execute** + +Operators: + +- `+` โ†’ **add** permission +- `-` โ†’ **remove** permission +- `=` โ†’ **set exactly** (override) + +### ๐Ÿงช Examples + +```bash +# Add execute permission for user +chmod u+x script.sh + +# Remove write permission from group +chmod g-w file.txt + +# Set read-only for everyone. `a` means all (user, group, others) +chmod a=r file.txt + +# Custom permission set for user, group, others +chmod u=rw,g=r,o= file.txt +``` + +## ๐Ÿ—‚๏ธ Numeric Permissions + +Each permission has a number: + +- `r` = **4** +- `w` = **2** +- `x` = **1** + +To calculate total: + +- `7` = 4 + 2 + 1 โ†’ **read + write + execute** +- `6` = 4 + 2 โ†’ **read + write** +- `5` = 4 + 1 โ†’ **read + execute** +- `0` = **no permissions** + +**Permissions** are defined in **three digits: user-group-others** (755, 644, etc.). + +### ๐Ÿงช Examples + +```bash +# rwx for user, rx for group and others +chmod 755 script.sh + +# rw for user, r for group and others +chmod 644 notes.txt + +# full access for user only +chmod 700 secret.sh +``` + +## Ownership + +Every file or directory has an owner and a group. To view ownership `ls -l` command is used. + +To change owner: + +```bash +sudo chown username file.txt +``` + +To change group: + +```bash +sudo chgrp groupname file.txt +``` + +To change both owner and group: + +```bash +sudo chown username:groupname file.txt +``` + +### ๐Ÿงช Examples + +```bash +# Change owner to alice +sudo chown alice document.txt + +# Change owner to bob and group to developers +sudo chown bob:developers script.sh +``` From 444567b066aa59cd63035253597a4d1cd077c57d Mon Sep 17 00:00:00 2001 From: Tharindu Lakshan Date: Wed, 6 Aug 2025 00:06:58 +0530 Subject: [PATCH 2/2] update file-permissions.md --- .../03_Users_and_Permissions/file-permissions.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Week 1 - Linux Fundamentals/03_Users_and_Permissions/file-permissions.md b/Week 1 - Linux Fundamentals/03_Users_and_Permissions/file-permissions.md index 62b1936..00feeae 100644 --- a/Week 1 - Linux Fundamentals/03_Users_and_Permissions/file-permissions.md +++ b/Week 1 - Linux Fundamentals/03_Users_and_Permissions/file-permissions.md @@ -68,7 +68,7 @@ chmod 644 notes.txt chmod 700 secret.sh ``` -## Ownership +## ๐Ÿ‘ค Ownership Every file or directory has an owner and a group. To view ownership `ls -l` command is used.