LPIC-1 Exam 101 free question 9 / 10 · Domain 4: Devices, Linux Filesystems, Filesystem Hierarchy Standard
You ran chmod g+w,o=r run.sh on the file run.sh, which ls -l shows as -rwxr-x--x. Which octal value of the permissions after the command is correct?
- 725
- 775
- 774
- 724
Show the answer and explanation
Answer: C
Why this is correct
The original -rwxr-x--x is owner rwx (4+2+1=7), group r-x (4+1=5), and other --x (1), which is 751. In the symbolic form of chmod, + adds the selected bits to the original bits, and = leaves only the selected bits and removes the bits that are not written. With g+w, w is added to the group's r-x and it becomes rwx (7), and with o=r other becomes only r (4). The owner is untouched, so it stays 7. The result is -rwxrwxr--, which is 774 in octal.
Why the other options are wrong
"775" … The 7 for the group is right. o=r makes 'other' only r, and the original x is removed. With o+r the x would remain and it would be r-x (5), but because it is =, it becomes r-- (4).
"724" … The 4 for other is right. g+w adds w to the group's original r-x, and the original bits remain. With g=w it would be -w- (2), but because it is +, it becomes rwx (7).
"725" … Both are wrong. The group is + so w is added to the original r-x, giving 7, and other is = so the x is removed and only r is left, giving 4. 725 is a value calculated by treating + as = and = as +.
The steps of the calculation
Symbolic specifications can be listed separated by commas and are applied from the left. To convert to octal, add r=4, w=2, and x=1 for each group of three characters. Remember that + and - add and subtract from the original value, and = discards the original value and replaces it, and you will not mix them up. When you specify in octal (chmod 774 run.sh), every group is replaced by that value.
Go to the LPIC-1 Exam 101 practice app (10 free questions; purchase unlocks all questions)