Code Reference

Permissions Basics

Bash · Reference cheat sheet

Permissions Basics

Bash · Reference cheat sheet


📋 Overview

Unix files have permission bits controlling who can read, write, or execute them. Understanding ls -l, chmod, and ownership prevents “Permission denied” confusion.

🔧 Core concepts

SymbolMeaning
rRead
wWrite
xExecute (run file / enter directory)
User / Group / OtherThree permission triples
chmodChange mode bits
chownChange owner (often needs admin)

Example ls -l mode: -rwxr-xr-- → file; owner rwx, group r-x, others r--.

💡 Examples

Inspect permissions:

ls -l hello.sh
# -rw-r--r-- 1 sam sam 40 Jul 10 09:00 hello.sh

Make a script executable:

chmod +x hello.sh
ls -l hello.sh
./hello.sh

Numeric modes (common):

chmod 644 notes.txt   # rw-r--r--
chmod 755 script.sh   # rwxr-xr-x
chmod 600 secret.env  # rw-------

Directories need execute to enter:

mkdir private
chmod 700 private
cd private
pwd

⚠️ Pitfalls

  • Execute bit on a directory means “traverse,” not “run like a program.”
  • chmod -R is powerful — easy to lock yourself out of a tree.
  • Scripts need both read and execute for ./script; bash script only needs read.
  • On Windows filesystems mounted in WSL/Git Bash, permission bits may not behave like native Linux.

On this page