// 02 — survival kit
FILESYSTEM
& PERMISSIONS
Linux keeps everything in one big tree of folders, starting from /. Every file has an owner and a set of rules about who can read, write, or run it. Once you understand this, "permission denied" stops being scary.
THE FILESYSTEM TREE
On Windows you have C:\ and D:\. Linux has one single tree that starts at / (called "root" or "slash"). Everything — including USB drives and network shares — lives somewhere inside this tree.
As a developer, you only need to know a handful of these folders:
~/ (your home folder). Everything else you'll mostly touch when you install software or debug a server.
ROOT VS YOUR USER
Linux has a special all-powerful user called root. Root can do anything — read any file, delete anything, change any setting. Your regular user account can only touch your own files and a few shared things.
You never log in as root day-to-day. Instead, you use sudo to run a single command with root power when you need to.
Runs one command as root. You'll be asked for your own password (not root's). Think of it as a permission slip for a single command.
Prints the current user's name. Useful when you're not sure whether you're running as root or your regular user.
When Should You Use sudo?
A simple rule: use sudo when the command touches something outside your home folder.
READING PERMISSIONS
Every file and folder in Linux has permissions attached. When you run ls -la, the first column of each line shows them. Let's decode it.
Breaking Down the Permission String
Take -rw-r--r-- and read it in four parts:
- = file d = folder
Each block of 3 characters uses the letters r (read), w (write), x (execute). A dash (-) means that permission is off.
x) on a folder means "can enter this folder." You need it to be able to cd into a directory. On a file it means "can run this as a program."
CHANGING PERMISSIONS
Changes the permissions of a file or folder. You'll use it most often to make a script executable or fix a file that's locked down too tight.
The easy way — symbolic
The number way — octal
Each permission group (owner, group, others) gets a number. r=4, w=2, x=1. Add them up.
Changes who owns a file. You'll need this when a file was created by root and you want your own user to be able to edit it.
touch test.sh, check its permissions with ls -la test.sh, then make it executable with chmod +x test.sh and run ls -la test.sh again. You'll see the x appear in the permission string.