02 — File System & Navigation¶
Navigation: ← 01 — Introduction | Notes Index | Next → 03 — Users & Groups Exercise: Exercise 02
The Linux File System — One Big Tree¶
On Windows, files are organized under drive letters: C:\, D:\, etc. Linux is different. Everything lives under a single root directory simply called / (a forward slash). There are no drive letters.
Think of it as one big tree:
/ ← everything starts here (the "root")
├── home/ ← where your personal files live
│ └── jahid/ ← your home folder (like C:\Users\jahid on Windows)
├── etc/ ← configuration files for the whole system
├── var/ ← files that change often (like logs)
├── bin/ ← essential programs (ls, cp, cat...)
├── tmp/ ← temporary files (wiped on reboot)
└── ...
Important Folders to Know¶
| Folder | What lives there | Example |
|---|---|---|
/home/ |
Personal files for each user | /home/jahid/Documents |
/etc/ |
System configuration files | /etc/hosts, /etc/passwd |
/var/log/ |
Log files (error messages, activity) | /var/log/syslog |
/bin/ and /usr/bin/ |
Programs you can run | /usr/bin/python3 |
/tmp/ |
Temporary scratch space | Safe to write test files here |
/root/ |
Home folder of the root (admin) user | Only root can access this |
You don't need to memorize all of these right now. Just know that /home/yourname is your space, and the rest is system territory.
Paths — How to Address a File¶
A path is the address of a file or folder. There are two types:
Absolute Path¶
Starts with / — tells the full location from the root.
This always works no matter where you currently are.
Relative Path¶
Does not start with / — location is relative to where you currently are.
This only works if you are already inside /home/jahid/.
Special Shorthand Symbols¶
| Symbol | Meaning | Example |
|---|---|---|
~ |
Your home directory | ~/notes = /home/jahid/notes |
. |
The current directory you are in | ./script.sh = run script in current folder |
.. |
The parent (one level up) | cd .. goes up one folder |
- |
The previous directory you were in | cd - jumps back |
Navigating the File System¶
pwd — Where am I right now?¶
pwd stands for "Print Working Directory". It tells you your current location.
Example output:
Run this whenever you feel lost and need to know where you are.
ls — What is in this folder?¶
Example output:
ls just lists the names. But it has useful flags:
The -l flag means "long format" — shows details like permissions, owner, size, and date.
Example output:
drwxr-xr-x 2 jahid jahid 4096 Jun 20 10:00 Documents
-rw-r--r-- 1 jahid jahid 512 Jun 19 08:30 notes.txt
Reading this line: d means directory, rw-r--r-- is the permissions, jahid is the owner, 512 is the size in bytes, and the rest is the date and name.
The -a flag means "all" — shows hidden files too. In Linux, any file starting with . is hidden.
Example output:
The .bashrc file is your shell configuration — it was always there, just hidden.
-l for long format, -h for "human-readable" sizes (shows 4.0K instead of 4096).
You can combine flags: ls -lah shows everything in long format with human-readable sizes including hidden files.
cd — Move to a different folder¶
cd stands for "Change Directory". After running this, you are now inside Documents.
Jump directly to /etc using an absolute path.
Go back to your home directory from anywhere. This is the same as cd /home/jahid.
Go up one level. If you are in /home/jahid/Documents, this takes you to /home/jahid.
Go back to the previous directory. Handy when you've jumped somewhere and want to return quickly.
Creating and Deleting Files & Folders¶
touch — Create an empty file¶
What it does: If notes.txt doesn't exist, it creates an empty file. If it already exists, it just updates the "last modified" timestamp without changing the content.
mkdir — Create a folder¶
What it does: Creates a new directory called projects.
The -p flag means "parents" — it creates all the folders in the path at once, even if projects and linux don't exist yet. Without -p, this command would fail if projects didn't exist.
cp — Copy a file or folder¶
What it does: Copies notes.txt and names the copy notes-backup.txt. The original stays untouched.
Copies notes.txt into the /tmp/ folder, keeping the same filename.
The -r flag means "recursive" — required when copying a directory. It copies the folder and everything inside it. Without -r, copying a directory fails.
mv — Move or rename a file¶
What it does: Renames the file. There is no separate "rename" command in Linux — mv handles both moving and renaming.
Moves notes.txt into the /tmp/ folder.
rm — Delete a file¶
What it does: Deletes the file. There is no Recycle Bin. Once deleted, it is gone.
The -r flag (recursive) is required to delete a folder and everything inside it.
-r (recursive) + -f (force, no confirmation prompts). This is a powerful and dangerous command. Double-check your path before running it — rm -rf / would delete everything on the entire system.
Beginner tip: Before deleting something important, copy it to
/tmp/first. If you don't need it after a reboot, then it's safe to delete.
rmdir — Delete an empty folder¶
Only works if the folder is completely empty. Use rm -r for folders with content.
Viewing File Contents¶
cat — Print a file's contents¶
What it does: Reads the file and prints all of it to the terminal at once. Good for short files.
The -n flag adds line numbers to the output. Useful when reading scripts or config files.
If a file is very long,
catwill flood your terminal. Uselessinstead.
less — Read a file one page at a time¶
What it does: Opens the file in a scrollable viewer.
| Key | Action |
|---|---|
↑ / ↓ |
Scroll up / down one line |
Space |
Scroll down one page |
b |
Scroll back one page |
/word |
Search for "word" |
n |
Jump to next search match |
q |
Quit |
head — Show the beginning of a file¶
Shows the first 10 lines by default.
The -n 20 flag shows the first 20 lines instead.
tail — Show the end of a file¶
Shows the last 10 lines by default.
Shows the last 20 lines.
The -f flag means "follow" — the terminal keeps watching the file and shows new lines as they are added. This is very useful for watching log files in real-time. Press Ctrl + C to stop.
Finding Files¶
find — Search for files¶
Breaking this down:
- find — the command
- /home — where to search (the /home directory and everything inside it)
- -name "*.txt" — find files whose name matches this pattern (* means "anything")
Search the entire system for a file named nginx.conf. You may see "Permission denied" errors for some system folders — that's normal for regular users.
-mtime -7 means "modified in the last 7 days". The - before 7 means "less than 7 days ago".
-size +100M means "files larger than 100 megabytes". Useful for finding what's eating up disk space.
grep — Search for text inside files¶
What it does: Reads the file and prints only the lines that contain the word "error".
-i means "ignore case" — matches "Error", "ERROR", "error", etc.
-n shows the line number alongside each match. Helpful when you need to jump to a specific line.
-r means "recursive" — searches all files inside the projects folder and its subfolders.
-v means "invert" — shows all lines that do not contain "debug". Useful for filtering out noise.
Checking Disk Space¶
df -h — How full are my disks?¶
df stands for "Disk Free". The -h flag makes sizes human-readable (GB, MB instead of bytes).
Example output:
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 50G 18G 30G 38% /
tmpfs 3.8G 0 3.8G 0% /dev/shm
The Use% column is the one to watch. If it hits 95%+, you need to free up space.
du -sh — How much space does a folder use?¶
du stands for "Disk Usage".
- -s means "summary" (one total line instead of every subfolder)
- -h means "human-readable"
Example output:
Links — Two Ways to Point to a File¶
Hard Link¶
Creates another name for the same file. Both file.txt and hardlink.txt point to the same data on disk. Deleting one does not delete the data — it only disappears when the last link is removed.
Symbolic (Soft) Link¶
-s creates a symbolic link — like a shortcut. ~/nginx.conf is a pointer to the original file. If the original is deleted, the link breaks.
Symlinks are used constantly in Linux. For example, /usr/bin/python is often a symlink to /usr/bin/python3.11.
Navigation: ← 01 — Introduction | Notes Index | Next → 03 — Users & Groups Exercise: Exercise 02