chmod Symbolic Mode

chmod changes file permissions. The symbolic mode uses letters - it's human-readable and flexible.

Basic Syntax

hljs bash
chmod [who][operation][permission] file
  • who: u (owner), g (group), o (others), a (all)
  • operation: + (add), - (remove), = (set exactly)
  • permission: r (read), w (write), x (execute)

Adding Permissions

Terminal
$ls -l script.sh
-rw-r--r-- 1 user user 1024 script.sh
$chmod u+x script.sh
$ls -l script.sh
-rwxr--r-- 1 user user 1024 script.sh

u+x = add execute permission for owner.

Removing Permissions

Terminal
$chmod o-r file.txt

o-r = remove read permission from others.

Setting Exact Permissions

Terminal
$chmod u=rw,g=r,o= file.txt
$ls -l file.txt
-rw-r----- 1 user user 1024 file.txt

= sets exactly these permissions, removing any others.

Common Examples

Make Script Executable

Terminal
$chmod +x script.sh

Without specifying who, +x adds execute for all classes.

Remove All Access for Others

Terminal
$chmod o= private.txt

o= with no permissions removes all access for others.

Give Group Read/Write

Terminal
$chmod g+rw shared.txt

Make Private (Owner Only)

Terminal
$chmod u=rw,go= secret.txt
$ls -l secret.txt
-rw------- 1 user user 1024 secret.txt

go= Shorthand

go= means "group and others, set to nothing." It's a quick way to remove all non-owner permissions.

Multiple Changes at Once

Terminal
$chmod u+x,g+w,o-r file

Separate multiple changes with commas.

Recursive Changes

Terminal
$chmod -R g+w project/
(all files in project/ get group write)

-R applies changes recursively to all files and subdirectories.

Careful with -R

Recursive changes affect everything. Be specific about what you're changing. chmod -R 777 / is a disaster.

Reference Another File

Terminal
$chmod --reference=template.txt newfile.txt

Copy permissions from one file to another.

Real-World Scenarios

Downloaded Script Won't Run

Terminal
$./deploy.sh
bash: ./deploy.sh: Permission denied
$chmod +x deploy.sh
$./deploy.sh
Deploying...

Shared Project Directory

Terminal
$chmod g+rwx /shared/project
$chmod g+rw /shared/project/*

Secure Config File

Terminal
$chmod 600 ~/.ssh/id_rsa
$chmod u=rw,go= ~/.ssh/id_rsa
(same thing, symbolic)
Knowledge Check

What does `chmod u+x,go-w file` do?

Quick Reference

CommandEffect
chmod +x fileAdd execute for all
chmod u+x fileAdd execute for owner
chmod g+w fileAdd write for group
chmod o-rwx fileRemove all for others
chmod u=rw,go=r fileSet owner rw, everyone r
chmod -R g+w dir/Recursive group write

Key Takeaways

  • Symbolic mode: [who][+/-/=][permissions]
  • + adds, - removes, = sets exactly
  • u = owner, g = group, o = others, a = all
  • Combine with commas: u+x,g+w
  • -R for recursive changes (use carefully)

Next: chmod numeric mode - the faster way.