📁Files, Folders & Navigation
Understand paths, directories, and how to move around your computer
Files, Folders & Navigation
Everything on your computer — every photo, every document, every application — lives inside a file system. The file system is a giant tree of folders (also called directories) and files. Learning how to navigate it from the terminal is one of the most important skills you can develop.
1. The File System Tree
Think of your computer's storage as an upside-down tree. At the very top is the root, and everything branches downward from there.
Visual Tree Diagram
/ ← Root (the very top)
├── Users/
│ └── yourname/ ← Your home directory (~)
│ ├── Desktop/
│ ├── Documents/
│ │ ├── report.pdf
│ │ └── notes.txt
│ ├── Downloads/
│ │ └── photo.jpg
│ ├── Music/
│ ├── Pictures/
│ └── Projects/
│ └── my-app/
│ ├── index.html
│ └── style.css
├── Applications/
├── System/
├── Library/
├── tmp/
└── var/
On macOS / Linux, the root of the tree is / (a single forward slash).
On Windows, each drive has its own root, like C:\ or D:\.
Key Directories
| Directory | What it contains |
|---|---|
/ | The root — the starting point of the entire file system |
/Users/yourname (Mac) or /home/yourname (Linux) | Your home directory — your personal space |
~/Desktop | Files on your desktop screen |
~/Documents | Your documents |
~/Downloads | Files downloaded from the internet |
/Applications (Mac) or /usr/bin (Linux) | Installed applications and programs |
/tmp | Temporary files (cleaned automatically) |
2. Absolute vs. Relative Paths
A path is the address of a file or folder. There are two kinds.
Absolute Path
An absolute path starts from the root (/) and spells out the full location:
/Users/yourname/Documents/report.pdfIt does not matter where you currently are — an absolute path always points to the same place. Think of it like a full street address including country and city.
Relative Path
A relative path starts from where you currently are:
Documents/report.pdfThis only works if you are currently inside /Users/yourname. If you moved somewhere else, the same relative path would point to a different (or nonexistent) location.
Special Symbols in Paths
| Symbol | Meaning | Example |
|---|---|---|
/ | Root directory (when at the start) or folder separator | /Users/yourname |
~ | Your home directory | ~/Documents is short for /Users/yourname/Documents |
. | The current directory | ./script.sh means "script.sh right here" |
.. | The parent directory (one level up) | ../photos means "go up one folder, then into photos" |
Examples
Suppose you are in /Users/yourname/Projects/my-app:
| What you type | Where it resolves to |
|---|---|
. | /Users/yourname/Projects/my-app |
.. | /Users/yourname/Projects |
../../Documents | /Users/yourname/Documents |
~/Downloads | /Users/yourname/Downloads |
/tmp | /tmp (absolute — ignores current location) |
3. The Home Directory (~)
Your home directory is your personal folder. Every user on a computer has one.
| OS | Home directory path | Shortcut |
|---|---|---|
| macOS | /Users/yourname | ~ |
| Linux | /home/yourname | ~ |
| Windows | C:\Users\yourname | %USERPROFILE% |
When you open a new terminal, you almost always start in your home directory. You can always return to it by typing:
cd ~Or simply:
cdBoth do the same thing.
4. Essential Navigation Commands
pwd — Print Working Directory
Shows you where you are right now.
pwdOutput:
/Users/yourname/Projects/my-app
Think of pwd as your GPS. Lost? Type pwd and you will know exactly where you are.
ls — List Files and Folders
Shows what is inside the current directory.
lsOutput:
Desktop Documents Downloads Music Pictures Projects
Useful Flags
| Flag | What it does | Example |
|---|---|---|
-l | Long format — shows permissions, size, date | ls -l |
-a | Show all files, including hidden ones (files starting with .) | ls -a |
-la | Combine both — long format + hidden files | ls -la |
-lh | Long format with human-readable file sizes (KB, MB) | ls -lh |
Example: ls -l
ls -lOutput:
total 16
drwxr-xr-x 4 yourname staff 128 Apr 20 10:30 Documents
drwxr-xr-x 2 yourname staff 64 Apr 18 09:15 Downloads
-rw-r--r-- 1 yourname staff 420 Apr 22 14:00 notes.txt
The columns are: permissions, link count, owner, group, size (bytes), date modified, and name. Lines starting with d are directories; lines starting with - are regular files.
Example: ls -a
ls -aOutput:
. .. .hidden-file .config Desktop Documents Downloads
Notice the . (current directory), .. (parent directory), and files starting with a dot — these are hidden files that ls alone does not show.
Example: ls -la
ls -laThis is the most common combination — it shows everything in detail. You will use this constantly.
Example: ls -la Full Output
total 48
drwxr-x---+ 18 yourname staff 576 Apr 25 09:00 .
drwxr-xr-x 5 root admin 160 Apr 10 08:00 ..
-rw------- 1 yourname staff 12 Apr 20 11:30 .bash_history
-rw-r--r-- 1 yourname staff 150 Apr 15 10:00 .bashrc
drwxr-xr-x 3 yourname staff 96 Apr 18 14:20 .config
-rw-r--r-- 1 yourname staff 200 Apr 22 08:45 .zshrc
drwx------+ 5 yourname staff 160 Apr 25 09:00 Desktop
drwx------+ 4 yourname staff 128 Apr 24 16:30 Documents
drwx------+ 3 yourname staff 96 Apr 23 12:15 Downloads
drwx------+ 3 yourname staff 96 Apr 10 08:00 Music
drwx------+ 3 yourname staff 96 Apr 10 08:00 Pictures
drwxr-xr-x 4 yourname staff 128 Apr 22 14:00 Projects
Reading this output column by column:
- Permissions (
drwxr-xr-x): Who can read, write, and execute. The first character isdfor directory or-for file. - Link count (
18): Number of hard links. - Owner (
yourname): Who owns the file. - Group (
staff): The group that owns it. - Size (
576): Size in bytes. - Date (
Apr 25 09:00): When it was last modified. - Name (
Desktop): The file or folder name.
Listing a Specific Directory
You do not have to cd into a folder to list its contents. Just pass the path as an argument:
ls ~/DocumentsThis shows the contents of Documents without changing your current location. You can combine this with flags:
ls -la ~/ProjectsListing Multiple Directories
ls ~/Documents ~/DownloadsThis shows the contents of both directories one after another.
cd — Change Directory
Moves you from one directory to another.
cd foldernameCommon Usage Patterns
| Command | What it does |
|---|---|
cd Documents | Move into the Documents folder (relative) |
cd /Users/yourname/Documents | Move to Documents using an absolute path |
cd .. | Go up one level (to the parent directory) |
cd ../.. | Go up two levels |
cd ~ | Go to your home directory |
cd | Also goes to your home directory (shortcut) |
cd / | Go to the root of the file system |
cd - | Go back to the previous directory you were in |
Walkthrough Example
pwd
# /Users/yourname
cd Documents
pwd
# /Users/yourname/Documents
cd ..
pwd
# /Users/yourname
cd Projects/my-app
pwd
# /Users/yourname/Projects/my-app
cd -
pwd
# /Users/yourname
# (cd - took us back to where we were before)
cd /
pwd
# /
# (we are now at the root of the file system)
cd ~
pwd
# /Users/yourname
# (back home)Pro tip: Press Tab while typing a folder name to auto-complete it. This saves time and avoids typos.
Tab Completion in Detail
Tab completion is one of the most powerful time-savers in the terminal. Here is how it works:
- Start typing a file or folder name:
cd Doc - Press Tab
- If there is only one match, the terminal completes it:
cd Documents/ - If there are multiple matches (e.g.,
DocumentsandDownloadsboth start withDo), press Tab twice to see all options - Type one more letter to disambiguate (e.g.,
cd Doc+ Tab =cd Documents/)
Tab completion also works with commands, not just paths. Start typing a command name and press Tab to complete it.
mkdir — Make Directory
Creates a new folder.
mkdir new-folderThis creates new-folder inside the current directory.
Create Nested Directories
Use -p to create multiple levels at once:
mkdir -p projects/web/my-siteThis creates projects, then web inside it, then my-site inside that — all in one command. Without -p, this would fail if projects or web did not already exist.
Create Multiple Directories at Once
mkdir photos videos musicThis creates three separate folders.
rmdir — Remove Empty Directory
Deletes a folder, but only if it is empty.
rmdir old-folderIf old-folder contains any files or subfolders, this command will fail with an error. This is a safety feature — it prevents you from accidentally deleting things.
Warning: To delete a folder that is not empty, you would use
rm -r foldername. Be very careful with this command — it deletes everything inside the folder permanently. There is no undo.
clear — Clear the Screen
Clears all the text from your terminal window.
clearYour terminal is not reset — your history and current directory are unchanged. It just gives you a clean screen to work with.
Keyboard shortcut: On most terminals, you can press Ctrl + L instead of typing clear.
Bonus: touch — Create an Empty File
While not a navigation command, touch is useful when exploring the file system:
touch myfile.txtThis creates an empty file called myfile.txt in the current directory. If the file already exists, it updates its "last modified" timestamp without changing its contents.
You can create multiple files at once:
touch index.html style.css app.jsWindows equivalent: In CMD, use type nul > myfile.txt. In PowerShell, use New-Item myfile.txt.
Bonus: tree — Visualize Directory Structure
The tree command displays the folder structure as a visual tree (you may need to install it first):
treeOutput:
.
├── css
│ └── style.css
├── images
│ ├── logo.png
│ └── banner.jpg
├── js
│ └── app.js
└── index.html
To limit the depth of the tree:
tree -L 2This only shows two levels deep. Very useful for large projects.
Install on macOS: brew install tree
Install on Ubuntu/Debian: sudo apt install tree
Windows equivalent: tree (built-in, but uses a different format). In CMD: tree /F to include files.
5. Mac/Linux vs. Windows Command Comparison
If you switch between operating systems, here is a handy reference:
| Task | Mac / Linux | Windows (CMD) | Windows (PowerShell) |
|---|---|---|---|
| Show current directory | pwd | cd (with no arguments) | pwd or Get-Location |
| List files | ls | dir | ls or Get-ChildItem |
| List all files (including hidden) | ls -a | dir /a | ls -Force |
| List in long format | ls -l | dir (default is detailed) | ls -l or Get-ChildItem |
| Change directory | cd foldername | cd foldername | cd foldername |
| Go up one level | cd .. | cd .. | cd .. |
| Go to home | cd ~ | cd %USERPROFILE% | cd ~ |
| Go to root | cd / | cd \ | cd \ |
| Go to previous directory | cd - | N/A | N/A |
| Create a directory | mkdir foldername | mkdir foldername | mkdir foldername |
| Create nested directories | mkdir -p a/b/c | mkdir a\b\c (auto-creates) | mkdir a/b/c (auto-creates) |
| Remove empty directory | rmdir foldername | rmdir foldername | rmdir foldername |
| Clear the screen | clear or Ctrl+L | cls | cls or Clear-Host |
| Path separator | / (forward slash) | \ (backslash) | \ or / (both work) |
Key Differences to Remember
- Path separator: Mac/Linux uses
/while Windows traditionally uses\. - Root: Mac/Linux has one root
/. Windows has a root per drive (C:\,D:\). - Case sensitivity: Mac/Linux file names are case-sensitive (
File.txtandfile.txtare different). Windows is case-insensitive. - Hidden files: On Mac/Linux, hidden files start with a dot (
.bashrc). On Windows, hidden is a file attribute set separately. - Home shortcut: Mac/Linux uses
~. Windows CMD uses%USERPROFILE%. PowerShell supports~.
6. Putting It All Together
Here is a real-world workflow combining everything you have learned:
# Step 1: Check where you are
pwd
# /Users/yourname
# Step 2: See what is here
ls
# Desktop Documents Downloads Music Pictures Projects
# Step 3: Go into Projects
cd Projects
# Step 4: Create a new project folder with subfolders
mkdir -p my-website/css my-website/js my-website/images
# Step 5: Go into the new project
cd my-website
# Step 6: See the structure you created
ls
# css images js
# Step 7: Check your location with the full path
pwd
# /Users/yourname/Projects/my-website
# Step 8: Go back home
cd ~
# Step 9: Clear the screen for a fresh start
clear7. Try It Yourself
Practice these exercises in your terminal. Type each command and observe the output.
Exercise 1: Explore Your Home Directory
cd ~
pwd
ls -laGoal: See all files in your home directory, including hidden ones. Count how many hidden files (starting with .) you find.
Exercise 2: Navigate Up and Down
cd /
ls
cd Users # or "cd home" on Linux
ls
cd ~
pwdGoal: Start at the root, explore the top-level directories, then navigate to your home directory. Use pwd to confirm where you are at each step.
Exercise 3: Create a Practice Folder Structure
cd ~
mkdir -p practice/level1/level2/level3
cd practice/level1/level2/level3
pwd
cd ../..
pwd
cd -
pwdGoal: Create deeply nested folders, navigate into them, use cd .. to go up, and use cd - to jump back. Predict the output of each pwd before you run it.
Exercise 4: Absolute vs Relative Paths
cd ~
mkdir -p path-test/folder-a path-test/folder-b
# Using relative path
cd path-test/folder-a
pwd
# Using absolute path (replace "yourname" with your actual username)
cd /Users/yourname/path-test/folder-b
pwd
# Go back using cd -
cd -
pwdGoal: Practice switching between absolute and relative paths. Notice that absolute paths work from anywhere, while relative paths depend on your current location.
Exercise 5: Clean Up
cd ~
rmdir practice/level1/level2/level3
rmdir practice/level1/level2
rmdir practice/level1
rmdir practice
rmdir path-test/folder-a
rmdir path-test/folder-b
rmdir path-test
lsGoal: Remove all the practice directories you created. Notice that rmdir only works on empty directories, so you must delete the deepest folders first. Verify with ls that everything was cleaned up.
8. Quick Reference Card
| Command | What it does |
|---|---|
pwd | Print current directory |
ls | List files and folders |
ls -la | List everything in detail |
cd folder | Move into folder |
cd .. | Move up one level |
cd ~ | Go home |
cd / | Go to root |
cd - | Go to previous directory |
mkdir name | Create a directory |
mkdir -p a/b/c | Create nested directories |
rmdir name | Remove empty directory |
clear | Clear the screen |
9. Common Mistakes and How to Fix Them
| Mistake | What happens | How to fix it |
|---|---|---|
Typing cd Docuemnts (typo) | "No such file or directory" error | Check your spelling. Use Tab completion to avoid typos. |
Using \ as path separator on Mac/Linux | Command fails or behaves unexpectedly | Always use / on Mac and Linux. |
| Forgetting you are in the wrong directory | Commands affect the wrong files | Always run pwd first when unsure. |
Trying rmdir on a non-empty directory | "Directory not empty" error | Delete the contents first or use rm -r carefully. |
| Using a relative path after changing directories | "No such file or directory" | Use absolute paths or cd back to the right directory first. |
| Spaces in folder names without quotes | Command treats each word as a separate argument | Wrap the name in quotes: cd "My Folder" |
Spaces in File and Folder Names
File and folder names with spaces need special handling in the terminal:
# This FAILS — the terminal thinks "My" and "Documents" are two separate arguments
cd My Documents
# This WORKS — wrap in quotes
cd "My Documents"
# This also WORKS — escape the space with a backslash
cd My\ DocumentsBest practice: When creating new folders and files, use hyphens (-) or underscores (_) instead of spaces: my-documents or my_documents.
Key Takeaways
- The file system is a tree starting from the root (
/). - Absolute paths start from root and always point to the same place.
- Relative paths start from your current location.
~is a shortcut for your home directory.pwd,ls, andcdare your daily navigation tools.mkdircreates folders;rmdirremoves empty ones.- Use Tab completion to type paths faster and avoid mistakes.
- On Windows, the main difference is
dirinstead oflsand\instead of/. - Always quote or escape file names that contain spaces.
- When in doubt, use
pwdto check where you are andlsto see what is around you.