To set specific permissions for the owner and group at the same time, you have two main ways: using Symbolic Notation (letters) or Numeric Notation (numbers).
1. Using Symbolic Notation (Comma Separated)
You can change both the owner (u) and the group (g) in a single command by separating the rules with a comma (no spaces).
Format: chmod u=[perms],g=[perms] filename
- Example: To give the owner
rwx(read, write, execute) and the group onlyrx(read, execute):chmod u=rwx,g=rx script.sh - Example: To add execute to both at once:
chmod ug+x script.sh
2. Using Numeric Notation (The "Math" Way)
This is often the fastest way to set exactly who has what. You use three digits: the 1st for Owner, 2nd for Group, and 3rd for Others.
Format: chmod [Owner][Group][Others] filename
- Example: Set Owner to
rwx(7) and Group torw-(6), and Others tor--(4):
(7 = 4+2+1 | 6 = 4+2 | 4 = 4)chmod 764 script.sh
Summary Table for Quick Reference:
| Target | Letter | Numeric Position |
|---|---|---|
| User (Owner) | u |
1st Digit (7xx) |
| Group | g |
2nd Digit (x7x) |
| Others | o |
3rd Digit (xx7) |
Pro Tip: If you want to set the same permissions for both owner and group to be exactly the same, you can use ug:
chmod ug=rw script.sh (This gives both the owner and group read/write access, and removes execute if it was there).