What is the difference between the symbolic and the absolute mode of chmod, and what does chmod u+s do?
Symbolic mode changes single rights relative to what is there (u+s, g-w); absolute mode sets all rights at once with an octal number. u+s adds the SUID bit for the owner.
Symbolic mode is who + operator + what:
- who:
u(owner),g(group),o(others),a(all), - operator:
+add,-remove,=set exactly, - what:
r,w,x, and the special bitss(SUID or SGID) andt(sticky).
Examples: chmod g-w file removes write for the group, chmod o=r file sets others to read only, chmod +x script makes a script executable for everyone.
Absolute mode (chmod 640 file) replaces the whole set at once. It is good for defining the complete state. Symbolic mode is good for changing one thing without touching the rest.
chmod u+s /bin/nano sets the SUID bit (the s goes in the owner's execute position). chmod u-s removes it again.
Only the file's owner or root may change its mode.
Go deeper:
man7.org: chmod(1) โ the exact grammar of symbolic modes (ugoa, +-=, rwxXst).