What is the difference between symbolic and octal modes in chmod?
Octal mode sets all permissions at once with numbers such as 640. Symbolic mode edits specific bits with letters, such as u+x or go-w, leaving the rest unchanged. Symbolic is safer for small tweaks; octal is better for setting a known final state.
Explain it simply
Octal is like writing the complete answer sheet again; symbolic is like correcting one answer with a pen.
Octal: three digits for owner, group, others. Read is 4, write is 2, execute is 1. Add them up: 6 = rw-, 5 = r-x. So chmod 640 f means owner rw-, group r--, others nothing. It overwrites everything.
Symbolic: who (u, g, o, a), an operator (+ add, - remove, = set exactly) and what (r, w, x). chmod u+x script.sh adds execute for the owner and touches nothing else. chmod go-rwx secret.txt removes all group and others access. chmod a=r f sets read-only for everyone.
There is also capital X: chmod -R u+rwX,go+rX dir gives execute only to directories and files that already have it, handy for recursive changes.
Example
touch run.sh
chmod 644 run.sh # -rw-r--r--
chmod u+x run.sh # -rwxr--r--
chmod go-r run.sh # -rwx------
ls -l run.sh
# -rwx------ 1 user user 0 ... run.shWhat to say in the interview
"Octal sets the complete permission state in one go, such as 640. Symbolic changes only the bits I name, like u+x. I use symbolic for quick adjustments and octal when I want an exact known result, for example in deployment scripts."
Common mistakes
- Using chmod -R 755 on a folder of data files, which makes every file executable.