From 3b6241d5f678823a70487ac61ee7a93cdba69b0b Mon Sep 17 00:00:00 2001 From: root Date: Tue, 15 Jul 2025 23:08:36 +0330 Subject: [PATCH] linux doc: perm doc --- Linux/LPIC1/19-chmod-chown.md | 150 ++++++++++++++++++++++++++++++++++ 1 file changed, 150 insertions(+) create mode 100644 Linux/LPIC1/19-chmod-chown.md diff --git a/Linux/LPIC1/19-chmod-chown.md b/Linux/LPIC1/19-chmod-chown.md new file mode 100644 index 0000000..c5c794f --- /dev/null +++ b/Linux/LPIC1/19-chmod-chown.md @@ -0,0 +1,150 @@ +# 📁 Linux File Permissions: A Quick & Clear Guide + +--- + +## 🔍 Example: Output of `ls -lh` + +Run this command in your terminal: + +```bash +ls -lh +``` + +Example output: + +```bash +drwxr-xr-x 3 root root 4.0K Jul 1 22:22 dir1 +-rw-r--r-- 1 root root 2.0G Jul 1 21:59 test2.tar +``` + +--- + +## 🧠 Understanding the Output Columns + +| Column | Description | +| -------------------- | --------------------------------------- | +| `d` / `-` | File type (`d` = directory, `-` = file) | +| `rwxr-xr-x` | Permissions (user, group, others) | +| `3` | Number of hard links | +| `root` | Owner (user) | +| `root` | Group | +| `4.0K` / `2.0G` | File size | +| `Jul 1 22:22` | Last modification date | +| `dir1` / `test2.tar` | File or directory name | + +--- + +## 🔤 First Character: File Type Indicator + +* `d` → Directory 📂 +* `-` → Regular file 📄 + +--- + +## 🔠 File Permissions Breakdown + +``` +drwxr-xr-x +│││ │ │ │ +│││ │ │ └─ Permissions for Others (o) +│││ │ └── Permissions for Group (g) +│││ └──── Permissions for User (u) +│└──────── File type (d = directory, - = file) +└───────── Read (r), Write (w), Execute (x) +``` + +--- + +## 🔐 Permission Symbols Explained + +| Symbol | Meaning | +| ------ | ------- | +| `r` | Read | +| `w` | Write | +| `x` | Execute | + +--- + +## 👥 Permission Entities + +| Symbol | Meaning | +| ------ | ------------ | +| `u` | User (owner) | +| `g` | Group | +| `o` | Others | +| `a` | All | + +--- + +## 🔢 Numeric Permission Values (Octal) + +| Value | Binary | Permissions | Meaning | +| ----- | ------ | ----------- | ---------------------- | +| 0 | 000 | --- | No permissions | +| 1 | 001 | --x | Execute only | +| 2 | 010 | -w- | Write only | +| 3 | 011 | -wx | Write + Execute | +| 4 | 100 | r-- | Read only | +| 5 | 101 | r-x | Read + Execute | +| 6 | 110 | rw- | Read + Write | +| 7 | 111 | rwx | Read + Write + Execute | + +--- + +## 🛠️ Changing Permissions with `chmod` + +### Syntax: + +```bash +chmod [permissions] [filename] +``` + +### Example (numeric): + +```bash +chmod 755 myscript.sh +``` + +### What does `755` mean? + +| Entity | Value | Permission | +| ------ | ----- | -------------------------- | +| User | 7 | rwx (read, write, execute) | +| Group | 5 | r-x (read, execute) | +| Others | 5 | r-x (read, execute) | + +### Recursive permission change: + +```bash +chmod -R +``` + +--- + +## 👑 Changing Ownership with `chown` + +### Syntax: + +```bash +chown [options] owner[:group] file +``` + +### Examples: + +Change owner only: + +```bash +sudo chown radin file.txt +``` + +Change owner and group: + +```bash +sudo chown radin:dev file.txt +``` + +Change owner and group recursively (for directories): + +```bash +sudo chown -R radin:dev files/ +```