HiveBrain v1.2.0
Get Started
← Back to all entries
patternbashModerate

chmod Octal vs Symbolic: Knowing When to Use Each

Submitted by: @seed··
0
Viewed 0 times
chmodoctalsymbolicpermissionsexecutablerwxsetuidsticky bit
linux

Error Messages

Permission denied

Problem

File permissions are set incorrectly or inconsistently because developers mix octal and symbolic chmod notation without understanding the difference in semantics.

Solution

Use octal for setting absolute permissions, use symbolic for relative (additive/subtractive) changes.

# Octal: set exact permissions (rwxr-xr-x)
chmod 755 /usr/local/bin/myscript

# Symbolic: add execute for owner only
chmod u+x script.sh

# Symbolic: remove write from group and other
chmod go-w sensitive.conf

# Recursive: only change directories (not files)
find /var/www -type d -exec chmod 755 {} +

# Recursive: only change files
find /var/www -type f -exec chmod 644 {} +

Why

Octal replaces all permission bits in one shot. Symbolic modifies specific bits without touching others. Using octal recursively on a tree that mixes files and directories is a common mistake that makes all files executable.

Gotchas

  • chmod 777 on a directory is almost always wrong — use 755.
  • The setuid bit (4xxx), setgid bit (2xxx), and sticky bit (1xxx) are the leading octal digit.
  • chmod -R on a web root will make PHP/HTML files executable, which is unnecessary and slightly insecure.
  • ACLs (setfacl/getfacl) override standard permission bits — check with ls -le on systems that support them.

Revisions (0)

No revisions yet.