15  15. Files, Folders, and Paths

Before you can move around your computer with Bash, you need a mental map of how the computer organizes files. This page gives you that map. The commands that use the map (pwd, ls, cd, …) are on the next pages.

15.1 Files and folders (directories)

  • A file holds data: a document, a photo, a program, a spreadsheet.
  • A folder holds files and other folders. In the command-line world a folder is usually called a directory. The two words mean the same thing.

Because folders can contain folders, two different files can have the same name as long as they are in different folders. For example, projects/website/README.txt and projects/data-analysis/README.txt are two completely separate files.

15.2 The file system is a tree

All of the folders on a computer form one big upside-down tree. The folder at the very top is called the root. On Mac and Linux the root is written as a single forward slash: /.

/                         <- the root (top of the tree)
├── Applications
├── Users
│   ├── maria             <- maria's home directory
│   │   ├── Desktop
│   │   ├── Documents
│   │   │   └── notes.txt
│   │   └── Downloads
│   └── sam               <- sam's home directory
└── ...

Windows organizes files by drive (usually C:). Git Bash (the Bash program we use on Windows) shows the C: drive as the folder /c, so the same ideas apply.

15.3 Your home directory and ~

Every user account has a personal folder called its home directory. Your Desktop, Documents and Downloads folders live inside it. When you open a new terminal window, you usually start out in your home directory.

/Users/maria

/c/Users/sam (Windows itself writes this as C:\Users\sam)

/home/maria

(Throughout this book, Maria uses a Mac and Sam uses Windows. Replace maria or sam with your own user name.)

The tilde character ~ is Bash’s shortcut for “my home directory”. These two lines mean exactly the same thing to Maria’s Bash on a Mac:

/Users/maria/Documents/notes.txt
~/Documents/notes.txt

~ is handy because it works for every user on every computer - your ~ is your home directory, my ~ is mine.

15.4 Paths: the address of a file

A path is the “address” of a file or folder. It lists the folders you pass through to reach it, separated by forward slashes /:

/Users/maria/Documents/notes.txt

Read it left to right: start at the root /, go into Users, then maria, then Documents, and there you will find notes.txt.

Windows users: use forward slashes in Bash

Windows normally writes paths with backslashes (C:\Users\sam). In Bash, always use forward slashes (/c/Users/sam). Bash treats a backslash as a special “escape” character, so backslash paths will not work the way you expect.

15.5 Full (absolute) paths vs. relative paths

At every moment, the terminal is “standing” in one folder. That folder is called your current working directory - think of it as the “you are here” marker on a map.

There are two ways to write the path to a file:

Full path (also called absolute path) Relative path
Starts from… the root / (or your home ~) your current working directory
Starts with… / or ~ anything else (a name, . or ..)
Example /Users/maria/Documents/notes.txt Documents/notes.txt
Works from any folder? Yes - it always means the same file No - its meaning depends on where you are

An analogy: a full path is like a complete mailing address (“123 Main St, Springfield”). A relative path is like directions from where you are standing (“two doors down on the left”).

For example, if Maria’s working directory is /Users/maria, the relative path Documents/notes.txt refers to /Users/maria/Documents/notes.txt. If her working directory were /Users/maria/Desktop, the same relative path would point to /Users/maria/Desktop/Documents/notes.txt - a different place (which probably doesn’t exist).

15.6 The special names . and ..

Every folder contains two special entries:

  • . (one dot) means this folder - the current directory.
  • .. (two dots) means the parent folder - the folder one level up.

You can use them inside relative paths. Using the practice files below, if you are standing in bash-tutorial-files/documents/notes:

Relative path Means
ideas.txt the file ideas.txt in the current folder
./ideas.txt the same file (. = this folder)
.. the parent folder, documents
../reports/annual-summary.txt go up to documents, then down into reports
../.. two levels up: bash-tutorial-files
../../music/song1.mp3 up two levels, then down into music

15.7 Hidden files (dot files)

Files and folders whose names start with a dot, such as .gitignore, .env, or .claude, are hidden. The plain ls command and the Mac’s Finder normally don’t show them. (Windows File Explorer shows most of them; it hides only items specially marked as hidden, such as Git’s .git folder.) Programs use hidden files to store settings. You will meet several important ones later: Git keeps its history in a hidden .git folder, and Claude Code keeps its settings in .claude folders.

15.8 Tips for naming files and folders

  • Avoid spaces. quarterly-report.txt or quarterly_report.txt is much easier to type in Bash than quarterly report.txt. If a name does contain spaces, you must put quotes around it, e.g. "My Documents/notes.txt". (Quotes get their own pages later.)
  • Treat names as case-sensitive. Linux treats Notes.txt and notes.txt as two different files. Mac and Windows usually don’t, but code you write often ends up running on Linux servers, so it’s best to be consistent.

Git Bash translates Windows drives into folders under /:

Windows writes Git Bash writes
C:\Users\sam\Documents /c/Users/sam/Documents
D:\photos /d/photos

If you ever need the Windows-style version of your current location (for example, to paste into File Explorer’s address bar), Git Bash’s pwd -W command prints it (e.g. C:/Users/sam/Documents). File Explorer accepts forward slashes too.

~ is not a real folder name. Bash replaces ~ with your home directory’s full path before running a command. This only happens when ~ appears at the start of a word and is not inside quotes. For example, ls ~/Documents works, but ls "~/Documents" looks for a folder literally named ~. This is one reason to avoid unnecessary quotes around paths that start with ~.

15.9 Practice files

Download the practice files and unzip them into the Documents folder in your home directory, so that you have the folder ~/Documents/bash-tutorial-files (the next pages assume this location): Download the practice files (zip)

Windows: is your Documents folder inside OneDrive?

If OneDrive backs up your Documents folder, the “Documents” you see in File Explorer is actually inside your OneDrive folder (whose name starts with OneDrive), not at ~/Documents. If cd ~/Documents/bash-tutorial-files later says “No such file or directory”, run ls ~ to find the OneDrive folder and look for Documents/bash-tutorial-files inside it (see Getting Bash on Your Computer).

bash-tutorial-files/
├── README.txt
├── documents/
│   ├── notes/
│   │   ├── ideas.txt
│   │   └── meeting-notes.txt
│   └── reports/
│       ├── annual-summary.txt
│       └── quarterly-report.txt
├── music/
│   ├── song1.mp3
│   └── song2.mp3
├── pictures/
│   ├── family.jpg
│   └── vacation.jpg
└── projects/
    ├── data-analysis/
    │   ├── analysis.py
    │   └── data.csv
    └── website/
        ├── index.html
        └── styles.css

The practice questions below assume this tree is located at /Users/maria/Documents/bash-tutorial-files (Maria is using a Mac).

Practice Questions

Easy

Question 1 · Short answer

What is another name for a “folder”?

A directory. The two words mean the same thing.

Question 2 · Short answer

What is the name of the folder at the very top of the file system, and how is it written on Mac and Linux?

It is called the root, and it is written as a single forward slash: /.

Question 3 · Multiple choice

What does ~ stand for in Bash?

  1. The root of the file system
  2. The current working directory
  3. Your home directory
  4. The parent of the current directory

c. ~ is shorthand for your home directory (for example /Users/maria). The root is / (a), the current directory is . (b), and the parent directory is .. (d).

Question 4 · Matching

Match each symbol with its meaning.

Symbol Meaning
1. / (by itself) A. the parent folder
2. . B. your home directory
3. .. C. the root of the file system
4. ~ D. the current folder

1 → C, 2 → D, 3 → A, 4 → B.

Question 5 · True or false

Two different files can have exactly the same name as long as they are stored in different folders.

True. A file is identified by its full path, not just its name. projects/website/README.txt and projects/data-analysis/README.txt are two different files.

Question 6 · Short answer

What is the “current working directory”?

It is the folder the terminal is currently “standing in” - the “you are here” marker. Relative paths are interpreted starting from this folder.

Medium

Question 7 · Multiple choice

Which of the following is a full (absolute) path?

  1. documents/notes/ideas.txt
  2. ../reports/annual-summary.txt
  3. /Users/maria/Documents/bash-tutorial-files/README.txt
  4. ./README.txt

c. It starts with /, the root, so it means the same file no matter where you are. Options a, b and d are relative paths: they start with a name, .. or ., so their meaning depends on the current working directory.

Question 8 · Write the path

Maria’s working directory is /Users/maria/Documents/bash-tutorial-files. Write the relative path to quarterly-report.txt.

documents/reports/quarterly-report.txt

(./documents/reports/quarterly-report.txt is also correct.)

Question 9 · Write the path

Write the full path to song2.mp3 in two different ways: once starting with / and once starting with ~.

  • /Users/maria/Documents/bash-tutorial-files/music/song2.mp3
  • ~/Documents/bash-tutorial-files/music/song2.mp3

Both are full paths because ~ always means Maria’s home directory, /Users/maria.

Question 10 · Write the path

Maria’s working directory is .../bash-tutorial-files/documents/notes. Write the shortest relative path to annual-summary.txt.

../reports/annual-summary.txt

.. goes up from notes to documents; from there, go down into reports.

Question 11 · Short answer

Starting in .../bash-tutorial-files/projects/website, which folder does the relative path ../.. refer to?

bash-tutorial-files. The first .. goes up from website to projects; the second goes up from projects to bash-tutorial-files.

Question 12 · Convert

A Windows user named Sam sees this path in File Explorer: C:\Users\sam\Documents\budget.xlsx. How should Sam type this path in Git Bash?

/c/Users/sam/Documents/budget.xlsx (or ~/Documents/budget.xlsx). The drive C: becomes the folder /c, and backslashes become forward slashes.

Question 13 · Short answer

Why are files such as .gitignore and .env not shown by a plain ls command or by the Mac’s Finder? What are such files usually used for?

Their names start with a dot, which makes them hidden files. Programs usually use hidden files and folders to store settings and configuration (for example Git’s .git folder or Claude Code’s .claude folder).

Hard

Question 14 · Predict

Maria’s working directory is /Users/maria/Desktop. She refers to the relative path Documents/notes.txt. Which file does that path point to, and why might she get a “No such file or directory” error?

It points to /Users/maria/Desktop/Documents/notes.txt, because relative paths start from the current working directory (the Desktop). Her Documents folder is actually /Users/maria/Documents, not inside the Desktop, so the file is probably not there. She could use ~/Documents/notes.txt or ../Documents/notes.txt instead.

Question 15 · Simplify

Simplify the relative path documents/notes/../reports/./annual-summary.txt (working directory: bash-tutorial-files).

documents/reports/annual-summary.txt.

documents/notes/.. goes into notes and right back out to documents, and ./ means “this folder”, so it adds nothing.

Question 16 · Short answer

A script uses the relative path data.csv. It works when Maria runs it from projects/data-analysis but fails when she runs it from her home directory. Explain why, and give one way to make it work from anywhere.

A relative path is interpreted from the current working directory. From projects/data-analysis, data.csv refers to the file in that folder; from the home directory it refers to ~/data.csv, which doesn’t exist. Using a full path, such as ~/Documents/bash-tutorial-files/projects/data-analysis/data.csv, works from any folder (or she can first move into the right folder).

Question 17 · Long answer

Give two reasons why it is a good idea to avoid spaces in file and folder names when you work with the command line, and explain what you must do if a name does contain a space.

  1. Bash uses spaces to separate the pieces of a command, so a name such as quarterly report.txt looks like two separate names (quarterly and report.txt).
  2. Names without spaces are faster to type and less error-prone (and the same goes for code, URLs and servers, where spaces often cause problems).

If a name does contain a space, put the whole path in quotes, for example "quarterly report.txt" (or put a backslash before the space: quarterly\ report.txt).

Question 18 · True or false

The command ls "~/Documents" lists the contents of your Documents folder.

False. Bash only replaces ~ with your home directory when the ~ is not inside quotes. With the quotes, Bash looks for a folder literally named ~. Use ls ~/Documents instead.

© 2025-2026 Y. Rosenthal. All rights reserved.