Files, folders and paths
Lesson 4 of 4
4Files, folders and paths
What the picture shows: A path lights up folder by folder from the root until it reaches the file.
This lesson is for people who use a computer by clicking only. If you already know paths, jump to the quiz at the bottom.
Map of this part
The concepts in order, click any one to jump to it:
Two ways into the same idea
A disk is like a big filing cabinet. A folder is a drawer, inside it are smaller drawers, and a file is a named sheet of paper. A path describes the way to the sheet: "the cabinet, then the school drawer, then the maths drawer, then the homework sheet". With that one line anyone finds the sheet without searching.
A file is a sequence of bytes with a name and metadata (size, dates, permissions). The file system is a tree rooted at / on Linux or C:\ on Windows. An absolute path starts at the root, like /home/sara/notes.txt; a relative one starts at the current folder, and .. means the parent folder.
Before You Start
🧭The operating system lesson
You know the disk keeps files and the kernel opens them on behalf of programs.
🖱️You have opened a folder before
On Windows, a Mac or a phone. That is enough.
The Core Idea
1A file: a name on a group of bytes
A file is a group of bytes kept on disk under a name. A photo, a text, a song, a program: all files, and the difference is in what the bytes mean, not in what a file is.
The extension after the dot, such as .txt or .jpg, is only a hint to programs about how to read the bytes. Change the extension and the bytes stay the same.
A text file means every byte in it is a character. These are all you will write in this track: code is text, settings are text, a script is text.
2A folder: an upside-down tree
A folder is a container holding files and other folders. Because folders hold folders, the shape becomes an upside-down tree: one root at the top and branches below.
On Linux the root is named just /. Under it sits home for users' files, etc for settings, and more. On Windows the root is C:\.
Your personal folder is where you always start, and its short name in the terminal is ~.
3A path: an address in one line
A path is the road from the root to a thing, folder names separated by /. Follow the picture: /home/sara/docs/report.txt means start at the root, enter home, then sara, then docs, and there is the file.
A path starting with / is absolute: it works from anywhere. One that does not is relative: it is counted from where you are. docs/report.txt works only when you are inside sara.
Two dots .. mean the parent folder, and one dot . means the current one. You will type both every day.
How It Works, Step by Step: How the computer finds a file from its path
The system reads the path from the left: it starts at the root.
It opens the first folder and looks inside it for the next name.
It repeats until the last name, then checks that it is a file.
If one name on the way is missing it stops and tells you: No such file or directory. The most common message you will ever read.
Try it without code
.. does. In the next lesson you do the same by typing instead of clicking.Myth vs Reality
| Myth | Reality |
|---|---|
| A file lives "inside" the program that opens it. | The file on disk is independent of any program. A program only reads it and writes it back. |
| Changing the extension converts the file. | It only changes which program opens it. The bytes themselves do not change. |
| Relative and absolute paths are the same thing. | Absolute starts at the root and works from anywhere; relative starts from where you are. |
Try it yourself
You are inside /home/sara. Which path reaches report.txt in /home/sara/docs?
A relative path is counted from where you are: from sara you enter docs and find the file. The first option starts at the root and looks for a docs folder directly under /, which does not exist.
Quick review cards
/, the top of the tree, with everything under it./ and works from anywhere; relative starts from your current place... mean?Check Your Understanding
Why are all code files text?
Because the programs that read and translate them expect characters, and because text can be compared and tracked line by line.
What happens if a path names a folder that does not exist?
The system stops at the first name it cannot find and returns No such file or directory.
Why is ~ quicker than typing your home folder in full?
Because it is a shortcut the shell replaces with the absolute path of your home folder, so it works for any user.
Resources for this lesson
Grouped by type. Start with the official docs for precision, or an article or video for the explanation.
Done with this lesson?
Sign in to save your progress.