cd ~
mkdir perms-practice && cd perms-practice
touch script.sh config.conf data.txt
ls -l
What This Does
Pro Tips
Common Mistakes to Avoid
ls -l script.sh
What This Does
Permission string has 10 characters: [type][owner perms][group perms][other perms]. Example: -rwxr-xr– means file(-), owner can read+write+execute(rwx), group can read+execute(r-x), others can read only(r–). r=read, w=write, x=execute, -=no permission.
You see something like -rw-r–r–. Break it down: - (file), rw- (owner can read/write), r– (group can read), r– (others can read).
Pro Tips
Common Mistakes to Avoid
echo '#!/bin/bash' > script.sh
echo 'echo "Hello from script"' >> script.sh
./script.sh
chmod +x script.sh
./script.sh
ls -l script.sh
What This Does
chmod changes permissions. +x adds execute permission for everyone. Before chmod, script can’t run (Permission denied). After, it executes. ls -l shows x permission added.
First ./script.sh fails with ‘Permission denied’. chmod +x makes it executable. Second ./script.sh runs successfully, prints ‘Hello from script’. ls -l shows -rwxr-xr-x (x added).
Pro Tips
./script.sh runs script in current directory#!/bin/bash is shebang (tells system which interpreter to use)Common Mistakes to Avoid
chmod -w config.conf
ls -l config.conf
echo 'test' > config.conf
chmod +w config.conf
echo 'test' > config.conf
ls -l config.conf
What This Does
-w makes file read-only (r–r–r–). Trying to write fails with ‘Permission denied’. +w restores write (rw-r–r–). Write succeeds.Pro Tips
+ adds permission, - removes permissionCommon Mistakes to Avoid
chmod u+x,g-w,o-r data.txt
ls -l data.txt
chmod u=rw,g=r,o= config.conf
ls -l config.conf
What This Does
u=owner, g=group, o=other. u+x adds execute for owner. g-w removes write for group. o-r removes read for others. Comma separates multiple changes. = sets exact permissions (replacing existing).
First command modifies data.txt permissions specifically for each category. Second command sets config.conf to: owner read+write, group read-only, others no permissions.
Pro Tips
+ adds, - removes, = sets exactlyCommon Mistakes to Avoid
chmod 755 script.sh
ls -l script.sh
chmod 644 config.conf
ls -l config.conf
chmod 600 data.txt
ls -l data.txt
What This Does
Numeric format: 3 digits for owner/group/other. Each digit is sum: r=4, w=2, x=1. 755 = rwxr-xr-x (7=4+2+1, 5=4+1, 5=4+1). 644 = rw-r–r–. 600 = rw——- (owner only). Faster than symbolic mode.
755 makes script executable by all (rwxr-xr-x). 644 makes config readable by all, writable by owner (rw-r–r–). 600 makes data private to owner (rw——-).
Pro Tips
Common Mistakes to Avoid
chmod 755 script.sh
chmod 644 config.conf
chmod 600 data.txt
ls -l
What This Does
Pro Tips
Common Mistakes to Avoid
ls -l
whoami
groups
id
What This Does
ls -l shows owner and group (columns 3 and 4). whoami shows your username. groups shows groups you belong to. id shows user ID (UID) and group IDs (GIDs). Ownership determines who can modify permissions.
ls -l shows your username as owner. whoami confirms your username. groups lists your groups. id shows numeric IDs.
Pro Tips
Common Mistakes to Avoid
mkdir testdir
chmod 644 testdir
ls testdir
cd testdir
chmod 755 testdir
cd testdir
pwd
What This Does
Directories need different permissions. r = list contents (ls). w = create/delete files inside. x = enter directory (cd). Without x, can’t cd even if you have r. 755 is standard for directories.
644 on directory allows ls but not cd (Permission denied). 755 allows both ls and cd. You successfully enter testdir after chmod 755
Pro Tips
Common Mistakes to Avoid
cd ~/perms-practice
mkdir -p project/{src,tests,docs}
touch project/src/app.js project/tests/test.js project/docs/readme.md
ls -lR project
chmod -R 755 project
ls -lR project
What This Does
Pro Tips
Common Mistakes to Avoid
cd ~
chmod -R 755 perms-practice
rm -r perms-practice
ls
What This Does
Set 755 to ensure we can delete everything (write permission). rm -r removes directory tree. Good practice: check permissions before rm if deletion fails.
perms-practice directory and all contents removed. Clean workspace.
Pro Tips
Common Mistakes to Avoid