Calculate Numeric Permissions
Calculate Numeric Permissions
You have seen a mode such as 640; now let's work out the number instead of memorizing it. Within each permission triplet, read has value 4, write has value 2, and execute has value 1. Add the values you want for that one class.
The three positions are owner, group and others, in that order. For the teacher's report, owner read/write is 6, group read is 4, and no ordinary others bits is 0. The result is 640, not a single quantity describing how secure the file is.
What you’ll learn
- Calculate owner, group and others permissions from 4, 2 and 1.
- Translate 640 into rw-, r-- and --- in the correct order.
Three digits encode three separate classes
Owner digit
Read 4 plus write 2 gives 6.
6 → rw-Group digit
Read alone gives 4.
4 → r--Others digit
No ordinary permissions gives 0.
0 → ---
Translate 640 into three permission triplets
Prepare the example
Use a fresh folder and create the empty marks.txt shown below. It gives us one owned file to change. We are setting ordinary permissions; special bits and directory meanings need their own explanation, so do not add a leading digit until you understand that additional role.
Bash · Linux terminal
touch marks.txt
chmod 640 marks.txt
ls -l marks.txtExpected behavior; machine-dependent details
The mode begins -rw-r-----.The touch line creates the file without supplying report text. chmod 640 marks.txt then replaces its ordinary bits with the requested triplets. ls -l should display owner rw-, group r-- and others --- in that order.
Calculate each digit independently. Read plus write is 4 + 2 = 6; read plus execute is 4 + 1 = 5; write plus execute is 2 + 1 = 3. These are combinations of separate bits, not decimal access levels. A numeric mode can remove existing ordinary bits as well as add requested ones, which is why you should read the current and desired modes before using it.
Build each digit from read, write and execute
Numeric chmod expresses each permission set as a number. Once you understand the three base values, modes such as 644, 755 and 700 become easy to decode.
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) = 4w(write) = 2x(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:
- User (owner)
- Group
- 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)
Apply complete modes and verify the triplets
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)
Break each octal digit into permission values
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)
Translate octal values into read, write and execute permissions
Try changing permissions on a few test files to get comfortable. You'll be mastering Linux file permissions in no time!
Try it, then check the worked answer
Your task: What does the owner digit 6 mean?
Use a fresh folder and create the empty marks.txt shown below. It gives us one owned file to change. We are setting ordinary permissions; special bits and directory meanings need their own explanation, so do not add a leading digit until you understand that additional role.
Bash · complete example for this question
touch marks.txt
chmod 640 marks.txt
ls -l marks.txtExpected behavior; machine-dependent details
The mode begins -rw-r-----.Worked answer
Read plus write: 4 + 2.
The owner digit 6 combines read and write. It does not include execute. For the second question, put each computed digit in its class position: owner first, group second, others third. Reversing positions changes who gets the permission even when the same digits appear.
Check your decision
Check the important distinction
Calculate each digit for the correct access class
Compute a triplet from 4, 2 and 1, then place its result in the correct class position. Use numeric notation when specifying a complete ordinary mode is your intent. If you want to adjust only selected existing bits, compare symbolic notation rather than accidentally replacing unrelated permissions.
Reaching the recap and completing the quizzes are separate milestones.