A triple can be written as one digit, and the whole mode as three. That way you set the permissions in full with a single command.
Each letter has a weight: r is 4, w is 2, x is 1. A triple's digit is the sum of the allowed letters: rw- is 6, r-x is 5, r-- is 4, --- is 0. The three digits follow the triples' order: owner, group, others. 640 is rw-r-----.
stat prints the mode as a number and as a string: 644 -rw-r--r-- for /etc/passwd and 640 -rw-r----- for /etc/shadow.
chmod 640 file sets all three triples at once. Symbolic notation changes one place; a number sets the whole mode. A number is handy when you know what the whole mode should become.
chmod -R 777 directory gives everyone read, write, and run on every file in the tree. The denial goes away, and so does the protection: anyone can change anyone's files.
What will stat -c '%A' deploy.sh print after chmod 750 deploy.sh?
-
The digits follow the triples' order: owner, group, others. The first, 7, belongs to the owner, and the last, 0, to others.
-
rw-is 6 (4 + 2). The group's digit is 5: 4 + 1, which isr-x. -
The owner has 7, all three letters: 4 + 2 + 1.
rw-would be 6.
7 = 4 + 2 + 1 gives the owner rwx, 5 = 4 + 1 gives the group r-x, and 0 gives others ---. Try it on any file of yours: chmod 750 file, then stat -c '%A' file.
Key points
-
A triple's digit is the sum of the weights:
ris 4,wis 2,xis 1; the three digits are owner, group, others. - Symbolic notation changes one place in the string; a number sets the whole mode.