Adding and Removing Rights
The command to change permissions is chmod (change mode). The easiest way to use it is "symbolic mode," which uses letters and mathematical operators to express changes relative to the current state.
The syntax is: chmod [who][operator][permission] filename
Who:
u— User (owner)g— Groupo— Othersa— All (equivalent tougo)
Operator:
+— Add permission-— Remove permission=— Set exactly to (removes all other permissions for that category)
Permission:
r— Readw— Writex— Execute
Examples: chmod u+x deploy.sh adds execute for the owner only; chmod go-w config.yaml strips write from group and others, leaving it writable only by the owner; chmod o=r public_doc.md sets others to exactly read-only, discarding any write or execute bits they had; chmod a+r notes.txt adds read for everyone; and multiple changes can be combined in one call, e.g. chmod u+x,g-w script.sh. Omitting the "who" entirely (chmod +x script.sh) is shorthand for a+x.
When to use symbolic mode:
Symbolic mode is ideal when you want to make incremental changes without knowing the current permissions. For example, chmod +x script.sh adds execute permission for everyone without affecting read or write permissions. You don't need to know if the file is currently 644 or 664—you just add execute.
Key Point: Symbolic mode is safer in automation scripts when you want to ensure a specific permission exists without accidentally removing others. For example,
chmod u+xguarantees the owner can execute the file but doesn't touch read or write permissions. In contrast,chmod 755would set all permissions explicitly, potentially removing write access if it existed. Use symbolic mode for additive changes; use octal mode when you need a guaranteed final state.