HomeTerminal & Command LineFiles, Folders & Navigation
beginner12 min read· Module 3, Lesson 2

📁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

DirectoryWhat 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
~/DesktopFiles on your desktop screen
~/DocumentsYour documents
~/DownloadsFiles downloaded from the internet
/Applications (Mac) or /usr/bin (Linux)Installed applications and programs
/tmpTemporary 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:

Terminal
/Users/yourname/Documents/report.pdf

It 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:

Terminal
Documents/report.pdf

This 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

SymbolMeaningExample
/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 typeWhere 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.

OSHome directory pathShortcut
macOS/Users/yourname~
Linux/home/yourname~
WindowsC:\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:

Terminal
cd ~

Or simply:

Terminal
cd

Both do the same thing.


4. Essential Navigation Commands

pwd — Print Working Directory

Shows you where you are right now.

Terminal
pwd

Output:

/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.

Terminal
ls

Output:

Desktop Documents Downloads Music Pictures Projects

Useful Flags

FlagWhat it doesExample
-lLong format — shows permissions, size, datels -l
-aShow all files, including hidden ones (files starting with .)ls -a
-laCombine both — long format + hidden filesls -la
-lhLong format with human-readable file sizes (KB, MB)ls -lh

Example: ls -l

Terminal
ls -l

Output:

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

Terminal
ls -a

Output:

. .. .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

Terminal
ls -la

This 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:

  1. Permissions (drwxr-xr-x): Who can read, write, and execute. The first character is d for directory or - for file.
  2. Link count (18): Number of hard links.
  3. Owner (yourname): Who owns the file.
  4. Group (staff): The group that owns it.
  5. Size (576): Size in bytes.
  6. Date (Apr 25 09:00): When it was last modified.
  7. 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:

Terminal
ls ~/Documents

This shows the contents of Documents without changing your current location. You can combine this with flags:

Terminal
ls -la ~/Projects

Listing Multiple Directories

Terminal
ls ~/Documents ~/Downloads

This shows the contents of both directories one after another.


cd — Change Directory

Moves you from one directory to another.

Terminal
cd foldername

Common Usage Patterns

CommandWhat it does
cd DocumentsMove into the Documents folder (relative)
cd /Users/yourname/DocumentsMove 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
cdAlso 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

Terminal
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:

  1. Start typing a file or folder name: cd Doc
  2. Press Tab
  3. If there is only one match, the terminal completes it: cd Documents/
  4. If there are multiple matches (e.g., Documents and Downloads both start with Do), press Tab twice to see all options
  5. 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.

Terminal
mkdir new-folder

This creates new-folder inside the current directory.

Create Nested Directories

Use -p to create multiple levels at once:

Terminal
mkdir -p projects/web/my-site

This 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

Terminal
mkdir photos videos music

This creates three separate folders.


rmdir — Remove Empty Directory

Deletes a folder, but only if it is empty.

Terminal
rmdir old-folder

If 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.

Terminal
clear

Your 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:

Terminal
touch myfile.txt

This 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:

Terminal
touch index.html style.css app.js

Windows 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):

Terminal
tree

Output:

. ├── css │ └── style.css ├── images │ ├── logo.png │ └── banner.jpg ├── js │ └── app.js └── index.html

To limit the depth of the tree:

Terminal
tree -L 2

This 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:

TaskMac / LinuxWindows (CMD)Windows (PowerShell)
Show current directorypwdcd (with no arguments)pwd or Get-Location
List fileslsdirls or Get-ChildItem
List all files (including hidden)ls -adir /als -Force
List in long formatls -ldir (default is detailed)ls -l or Get-ChildItem
Change directorycd foldernamecd foldernamecd foldername
Go up one levelcd ..cd ..cd ..
Go to homecd ~cd %USERPROFILE%cd ~
Go to rootcd /cd \cd \
Go to previous directorycd -N/AN/A
Create a directorymkdir foldernamemkdir foldernamemkdir foldername
Create nested directoriesmkdir -p a/b/cmkdir a\b\c (auto-creates)mkdir a/b/c (auto-creates)
Remove empty directoryrmdir foldernamermdir foldernamermdir foldername
Clear the screenclear or Ctrl+Lclscls or Clear-Host
Path separator/ (forward slash)\ (backslash)\ or / (both work)

Key Differences to Remember

  1. Path separator: Mac/Linux uses / while Windows traditionally uses \.
  2. Root: Mac/Linux has one root /. Windows has a root per drive (C:\, D:\).
  3. Case sensitivity: Mac/Linux file names are case-sensitive (File.txt and file.txt are different). Windows is case-insensitive.
  4. Hidden files: On Mac/Linux, hidden files start with a dot (.bashrc). On Windows, hidden is a file attribute set separately.
  5. 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:

Terminal
# 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 clear

7. Try It Yourself

Practice these exercises in your terminal. Type each command and observe the output.

Exercise 1: Explore Your Home Directory

Terminal
cd ~ pwd ls -la

Goal: 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

Terminal
cd / ls cd Users # or "cd home" on Linux ls cd ~ pwd

Goal: 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

Terminal
cd ~ mkdir -p practice/level1/level2/level3 cd practice/level1/level2/level3 pwd cd ../.. pwd cd - pwd

Goal: 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

Terminal
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 - pwd

Goal: 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

Terminal
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 ls

Goal: 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

CommandWhat it does
pwdPrint current directory
lsList files and folders
ls -laList everything in detail
cd folderMove into folder
cd ..Move up one level
cd ~Go home
cd /Go to root
cd -Go to previous directory
mkdir nameCreate a directory
mkdir -p a/b/cCreate nested directories
rmdir nameRemove empty directory
clearClear the screen

9. Common Mistakes and How to Fix Them

MistakeWhat happensHow to fix it
Typing cd Docuemnts (typo)"No such file or directory" errorCheck your spelling. Use Tab completion to avoid typos.
Using \ as path separator on Mac/LinuxCommand fails or behaves unexpectedlyAlways use / on Mac and Linux.
Forgetting you are in the wrong directoryCommands affect the wrong filesAlways run pwd first when unsure.
Trying rmdir on a non-empty directory"Directory not empty" errorDelete 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 quotesCommand treats each word as a separate argumentWrap 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:

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\ Documents

Best 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, and cd are your daily navigation tools.
  • mkdir creates folders; rmdir removes empty ones.
  • Use Tab completion to type paths faster and avoid mistakes.
  • On Windows, the main difference is dir instead of ls and \ instead of /.
  • Always quote or escape file names that contain spaces.
  • When in doubt, use pwd to check where you are and ls to see what is around you.