How to Use Numeric Mode with chmod

How to Use Numeric Mode with chmod

Welcome to this Linux tutorial! Today, we're going to learn how to use numeric mode with the chmod command to change file permissions. If you're just getting started with Linux, this lesson will give you a clear and beginner-friendly explanation of numeric (octal) permission values.

🎯 Why chmod Numeric Mode?

In Linux, every file and directory has permission settings that control who can read, write, or execute them. You can change these permissions using the chmod command. There are two main ways to use chmod:

  • Symbolic mode (like chmod u+x file.txt)
  • Numeric mode — this is what we’re covering in this tutorial

🔢 What Do the Numbers Mean?

Each permission is assigned a number:

  • r (read) = 4
  • w (write) = 2
  • x (execute) = 1

You add these values together to represent permissions. For example:

  • 7 = read + write + execute (4 + 2 + 1)
  • 6 = read + write (4 + 2)
  • 5 = read + execute (4 + 1)

Permissions are grouped into three categories:

  1. User (owner)
  2. Group
  3. Others

So when you see a command like:

chmod 755 script.sh

You're saying:

  • User: 7 (read, write, execute)
  • Group: 5 (read, execute)
  • Others: 5 (read, execute)

📂 Let’s Try It Step-by-Step

Step 1: Create a test file

touch myfile.txt

Step 2: View the current permissions

ls -l myfile.txt
-rw-r--r-- 1 user user 0 Jul  2 12:34 myfile.txt

Step 3: Now change permissions to 764

chmod 764 myfile.txt

Step 4: View the updated permissions

ls -l myfile.txt
-rwxrw-r-- 1 user user 0 Jul  2 12:34 myfile.txt

This means:

  • User: 7 (read, write, execute)
  • Group: 6 (read, write)
  • Others: 4 (read only)

🧠 Pro Tip

If you're ever unsure about what a number means, just break it into parts:

  • First digit = user
  • Second digit = group
  • Third digit = others

So, chmod 640 file gives:

  • User: 6 (read, write)
  • Group: 4 (read only)
  • Others: 0 (no permissions)

✅ Summary

That's it! You now know how to use numeric mode with chmod. It’s quick, powerful, and once you get used to the numbers, it becomes second nature.

Try changing permissions on a few test files to get comfortable. You'll be mastering Linux file permissions in no time!


Comments

💬 Please keep your comment relevant and respectful. Avoid spamming, offensive language, or posting promotional/backlink content.
All comments are subject to moderation before being published.


Loading comments...