Linux and Command-Line Basics
After "chmod 754 run.sh" is run on the file run.sh, which of the following is the permission notation shown at the start of the line from "ls -l run.sh"?
- A-rwxr-xr--
- B-r--r-xrwx
- C-rwxrw-r--
Show answer and explanation
Answer: A. -rwxr-xr--
Octal permissions are ordered, from the left, owner (user), group and others, and each digit is the sum of read r = 4, write w = 2 and execute x = 1. 7 = 4 + 2 + 1 is rwx, 5 = 4 + 1 is r-x and 4 is r--, so 754 becomes rwxr-xr--. The leading "-" means a regular file; a directory would show "d". With this setting the owner can read, write and execute, the group can read and execute, and other users can only read.
- A. Correct. 7 is rwx, 5 is r-x and 4 is r--.
- B. This reads the three digits in reverse order and corresponds to chmod 457. The octal digits are owner, group and others from the left.
- C. 5 is 4 + 1, that is r-x. rw- corresponds to 4 + 2 = 6.