
🎯 Have you ever encountered:
❌ “Permission denied”❌ “Cannot execute script”❌ “The file is here, but I can’t open it!”
Don’t panic! It’s not a system glitch — it’s permissions protecting you!
Today, we will start with the basics of “file permissions” to help you fully understand:
🔹 What are r, w, x?🔹 What does -rw-r–r– mean?🔹 Why can’t others modify your files?
—
📂 A relatable example: our “diary”
Imagine our Linux system as an office, where each file is a “folder” or “notebook”.
Permissions are like the labels on the cover:
👤 Owner → Us👥 Group → Our department colleagues🌍 Others → People from other departments in the company
—
🔐 The three brothers of file permissions: r / w / x
For “files”:
- • 📖
<span>r</span>(read) → Can open and read content (cat / less / vim) - • ✍️
<span>w</span>(write) → Can modify, delete, or overwrite (echo > / rm) - • 🚀
<span>x</span>(execute) → Can run as a program/script (./script.sh)
⚠️ Note: For files, <span>x</span> ≠ “enter”, but means “executable”! For directories, x means you can enter. Without <span>x</span>, no matter how good the script is, it won’t run!
—
📌 The most common permission:<span>-rw-r--r--</span>
What is this? Let’s break it down:
-rw-r--r--
│ │ │ │
│ │ │ └─ Others: r-- → read-only
│ │ └─── Group: r-- → read-only
│ └────── Owner: rw- → read and write
└───────── - indicates this is a "regular file"
✅ Meaning:
- • Owner: can read + modify
- • Group members: can only read, cannot modify
- • Others: can also only read, cannot modify
📌 This is the default permission when creating a regular file in Linux! → For example, when we <span>touch myfile.txt</span>, it has this permission!
—
🧠 A practical example:
$ touch diary.txt
$ echo "I had hot pot today" > diary.txt
$ ls -l diary.txt
-rw-r--r-- 1 alice alice 18 Apr 5 10:00 diary.txt
# Ourselves:
cat diary.txt # ✅ Can read
echo "So spicy!" >> diary.txt # ✅ Can write
# Colleague Bo (same group):
cat diary.txt # ✅ Can read
echo "Liar!" >> diary.txt # ❌ Permission denied!
# Visitor Charlie (others):
cat diary.txt # ✅ Can read (because r--)
rm diary.txt # ❌ Cannot delete (deleting requires w permission on the directory!)
—
🔧 How to modify file permissions?
Use the <span>chmod</span> command:
chmod 644 filename # → -rw-r--r-- (default)
chmod 600 filename # → -rw------- (only you can read and write)
chmod 755 filename # → -rwxr-xr-x (you can read, write, execute; others can read + execute)
chmod +x script.sh # → give everyone "executable" permission
🔢 Quick memory aid for numbers:
- • 4 = r (read)
- • 2 = w (write)
- • 1 = x (execute)
👉 4+2+1 = 7 → has all permissions👉 4+0+0 = 4 → read-only👉 6 = 4+2 → read + write (most common)
—
✅ Summary card (recommended to save!)
| Permission | Owner | Group User | Others | Usage |
<span>-rw-r--r--</span> |
rw- | r– | r– | Regular file, default permission |
<span>-rw-------</span> |
rw- | — | — | Private file (e.g., keys, configurations) |
<span>-rwxr-xr-x</span> |
rwx | r-x | r-x | Executable script/program |
📲 Share with friends learning Linux, so they won’t be confused about permissions anymore!